訪問www首頁不跳轉三級域名的三種方式 (struts welcome-file-list index.action問題)

問題:

在工程發佈的時候,首頁訪問一般都是www.xxx.com,如果首頁沒有動態action數據那麼沒有什麼問題;如果是action請求數據,則可能遇到訪問不到內容的情況,比方:

1.訪問www.xxx.com 無法訪問

2.訪問www.xxx.com 做跳轉,url跳轉到了www.xxx.com/index.html(或者其他的什麼),可以訪問到了,但是據說會影響網站的權重,至少不美觀。

解決方案:

如果你採用的技術爲是Java Struts Tomcat,有兩種解決方式。

方式一 Tomcat:

通過web.xml的方式,配置爲

1.修改web.xml

 

<welcome-file-list>
        <welcome-file>index.html</welcome-file>

        <welcome-file>index.jsp</welcome-file>

        <welcome-file>index.action</welcome-file>

</welcome-file-list>

其中前兩個自然不必說了,是不需要action請求訪問數據的方式。而index.action一般情況是無效的。那麼需要下邊一步

2.webcontent下面建立一個index.action的空文件,然後使用struts配置去跳轉,不然web找不到index.action這個文件,會報404錯誤。解釋:welcome-file-list的工作原理是,按照welcome-file的.list一個一個去檢查是否web目錄下面存在這個文件,如果存在,繼續下面的工作(或者跳轉到index.html頁面,或者配置有struts的,會直接struts的過濾工作)
方式二 Structs:

通過urlrewrite的方式,配置爲

<rule>
    <note>首頁</note>
    <from>^/$</from>
    <to type="forward">/index.action</to>
</rule>

這個方式也不陌生,主要from標籤的url匹配表達式的寫法即可。

方式三 Nginx:

這裏,如果是單次重定向用 redirect, 如果永久跳轉用 permanent,這裏用 permanent

     {
               listen       80;
               server_name  xxx.com www.xxx.com;
               index index.html index.php;
               root  /data/www/wwwroot;
               if ($http_host !~ "^www.xxx.com$") {
                       rewrite  ^(.*)    http://www.xxx.com$1 permanent;
                 }
               ........................
       }

參考:

http://blog.csdn.net/fruithardcandy/article/details/7275019

http://bbs.powereasy.net/forum67/thread-413426-1-575.aspx

http://honda418.iteye.com/blog/835246

https://yonghappy.com/2183

PHP參見:

http://www.haoxuee.com/IT/dedecms/132033.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章