2014-10-10 305 views
0

我一直在嘗試這一段時間。我想將例如wwww.example.com重定向到exmaple.com。.htaccess將www重定向到非www網頁

我試過的代碼片段幾個:

RewriteCond %{http_host} ^dansams\.co.uk [nc] 
RewriteRule ^(.*)$ http://www.dansams.co.uk/$1 [R=permanent,nc,L] 

....

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

還有更多,但沒有工作過。我的根目錄中有.htaccess文件,名爲'public_html'。我的所有網站內容都在該public_html文件夾中。當我嘗試的代碼所有這些不同的片段發生了什麼事時,當我嘗試www.example.com,它越來越採取的網址:

www.example.com/public_html 

該頁面顯示一些內容,但沒有三網融合和它也不是所有的索引內容。

任何與此有關的幫助將不勝感激。

在此先感謝

+0

什麼是你的DocumentRoot? – anubhava 2014-10-11 03:45:44

回答

0

試試這個:

RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
+0

它仍然需要我http://example.co.uk/public_html/ – Forrest 2014-10-10 22:39:23