2015-10-05 100 views
1

我對.htaccess編輯或正則表達式幾乎一無所知。我做了什麼,試圖讓我的網站重新定向從www版本non-www版本是我跟着張貼在這裏的答案:.htaccess將www重定向到非www無法正常工作

redirect www to non-www

不過,我得到的是,如果我進入www.example.com,我得到:

example.com/example.com/和我的網站上

404錯誤這是我的.htaccess文件:

#Adjust default time zone 
SetEnv TZ America/Toronto 

#Begin redirect www to non-www 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule^http://%1%{REQUEST_URI} [NE,R=301,L] 

# Google Analytics Integration - Added by cPanel. 
<IfModule mod_substitute.c> 
AddOutputFilterByType SUBSTITUTE text/html 
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i" 
</IfModule> 
# END Google Analytics Integration 

有人能告訴我我做錯了什麼嗎?

+0

你是如何在重定向的URL中獲得example.com/example.com /'的?您是否嘗試清除瀏覽器緩存? – anubhava

+0

配置文件或.htaccess中必須有其他內容。或者,也許該網站在一個子目錄中,並且目錄前綴存在一些問題。 –

回答

-1
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] 
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 

也就是說,檢查HTTP_HOST包含www和如果是這樣,重定向到非www與附加的REQUEST_URI。

+0

這正是OP已經做的。 –