非www到www.redirect并将index.html重定向到index.php
Im使用mod_rewrite将所有非www请求定向到www.url,使用以下代码非www到www.redirect并将index.html重定向到index.php,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,Im使用mod_rewrite将所有非www请求定向到www.url,使用以下代码 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,并且有几
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/保持您的规则如下:
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]
可能是完美的复制品,谢谢@anubhava