Php .htaccess具有多个规则的重定向

Php .htaccess具有多个规则的重定向,php,.htaccess,redirect,mod-rewrite,Php,.htaccess,Redirect,Mod Rewrite,基本上我想做的是: 1) 将任何.html请求重定向到.php页面 2) 如果发生任何404,则应重定向至www.domain.com 3) domain.com应重定向到www.domain.com 4) www.domain.com/index.html应重定向到www.domain.com 这是我的密码 RewriteEngine On RewriteRule ^(.*)\.html$ $1.php [L] <IfModule mod_rewrite.c> RewriteE

基本上我想做的是:

1) 将任何.html请求重定向到.php页面

2) 如果发生任何404,则应重定向至www.domain.com

3) domain.com应重定向到www.domain.com

4) www.domain.com/index.html应重定向到www.domain.com

这是我的密码

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]
重新编写引擎打开
重写规则^(.*)\.html$$1.php[L]
重新启动发动机
重写基/
重写规则^fr/(.)*$/[R=301,NC,L]#添加行
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。http://www.domsdain.com/index.php [L]
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
重写规则^(.*)$http://www.%{HTTP_HOST}/$1[R=301,L]
重写规则^(.*)索引\(php | html?$/$1[R=301,NC,L]

使用上述代码,第四条规则(www.domain.com/index.html应重定向到www.domain.com)不起作用

您可以重构以使用这些规则:

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]
确保清除浏览器缓存或使用新浏览器进行测试