非www到www。重定向并将index.html重定向到index.php

问题描述:

使用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://*.com/questions/234723/仿制htaccess的-RE直接www到非www) – opalenzuela

让你的规则是这样的:

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