2014-01-20 121 views
1

使用mod_rewrite將所有非www請求指向www。 URL使用下面的代碼非www到www。重定向並將index.html重定向到index.php

RewriteEngine On 
Options +FollowSymLinks 


# non-www to www resolve 
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC] 
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L] 

然而筆者近日從html的改變了索引頁.PHP並有仍然指向index.html頁面幾個外部鏈接。

只需添加一個301重定向在一個循環的結果,由於上述規則

#1 Permanent URL redirect 
Redirect 301 /index.html http://www.website.co.uk/ 

我怎樣才能適應這個代碼,以保持非www重定向和重定向也index.html的請求的index.php或www.website.co.uk/

+0

可能重複[通用htaccess的重定向到WWW非www](http://stackoverflow.com/questions/234723/仿製htaccess的-RE直接www到非www) – opalenzuela

回答

1

讓你的規則是這樣的:

DirectoryIndex index.php 

RewriteEngine On 
Options +FollowSymLinks 

# non-www to www resolve 
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC] 
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L] 

# index.html to/
RewriteCond %{THE_REQUEST} \s/index\.html [NC] 
RewriteRule ^/[L,R=301] 
+0

完美,謝謝@anubhava – AndyKing

+0

不客氣,很高興它解決了。 – anubhava