2013-01-12 64 views
0

我在Tomcat服務器上遇到了一些問題:我試圖將所有請求從裸域重定向到以www開頭的所有請求。 谷歌搜索和使用urlReWriteFilter的指導給了我相反的方向一些海洋觀測系統的例子(從裸域到www):Tomcat:如何將www子域重定向到裸體

<rule> 
    <note> 
     Moves all annoying www requests to the naked domain 
    </note> 
    <name>Domain Name Check</name> 
    <condition name="host" operator="notequal">www.maternal-beauty.co.il</condition> 
    <from>^(.*)$</from> 
    <to type="permanent-redirect">http://www.maternal-beauty.co.il$1</to> 
</rule> 

的問題是,當我只是刪除了「www'prefix,我沒有重定向。我請求的每個地址只是返回了corespomding頁面而沒有任何重定向。

<rule> 
    <note> 
     Moves all annoying www requests to the naked domain 
    </note> 
    <name>Domain Name Check</name> 
    <condition name="host" operator="notequal">maternal-beauty.co.il</condition> 
    <from>^(.*)$</from> 
    <to type="permanent-redirect">http://maternal-beauty.co.il$1</to> 
</rule> 

請注意,唯一的區別是我從condition元素和to元素中刪除了'www'prefix。 我無法弄清楚這裏有什麼問題。 如果它很重要,我使用的是Tomcat 7.0.34,當然還有org.tuckey.web.filters.urlrewrite.UrlRewriteFilter過濾器。

感謝您的回覆,

蓋伊

回答

1

這可能是從你想做什麼條條框框,但不能你與你的域名提供商,處理起來更容易嗎?我使用的大多數功能都允許您設置A記錄並轉發,通常稱爲控制面板或控制檯。在你的情況下,這意味着有www的A記錄。版本(所有www版本都使用給定的IP地址並顯示www。域名),並將「裸域」轉發到www版本。