[英].htaccess redirection with multiple rules
Basically what I want to do is : 基本上我想做的是:
1) redirect any .html request to .php page. 1)将任何.html请求重定向到.php页面。
2) if any 404 happens , then it should redirect to www.domain.com 2)如果发生任何404,则应重定向到www.domain.com
3) domain.com should be redirected to www.domain.com 3)domain.com应该重定向到www.domain.com
4) www.domain.com/index.html should redirect to www.domain.com 4)www.domain.com/index.html应该重定向到www.domain.com
Here is my htaccess code 这是我的htaccess代码
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^fr/(.)*$ / [R=301,NC,L] # Added line
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . http://www.domsdain.com/index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]
With above code 4th rule (www.domain.com/index.html should redirect to www.domain.com) is not working 使用上述代码,第4条规则(www.domain.com/index.html应该重定向到www.domain.com)不起作用
You can refactor to use these rules: 您可以重构以使用以下规则:
ErrorDocument 404 http://www.examle.com/
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.(?:php|html) [NC]
RewriteRule ^ http://www.examle.com/ [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(.+)\.html$ $1.php [L,NC]
RewriteRule ^fr/(.)*$ / [R=301,NC,L]
Make sure to clear your browser cache or use a new browser for testing. 确保清除浏览器缓存或使用新的浏览器进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.