当index.php /

时间:2015-12-21 12:07:58

标签: php linux .htaccess

我的.htaccess文件中有以下代码,

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /home
RewriteRule ^home$ / [L,R=301]

成功将www.domainname.com/index.php重定向到www.domainname.com

但是,当www.domainname.com/index.php/提供的网址时,它无法重定向 (index.php后带斜杠的URL)

1 个答案:

答案 0 :(得分:2)

通过在两个规则中选择尾随斜杠来实现这​​一点:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /+index\.php [NC]
RewriteRule ^index\.php/?$ / [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /home [NC]
RewriteRule ^home/?$ / [L,NC,R=301]