.htaccess 从所有包含index.php的页面重定向到非index.php页面

wr98u20j  于 2023-03-23  发布在  PHP
关注(0)|答案(2)|浏览(139)

我有这个规则从index.php重定向

RewriteCond %{HTTP_HOST} ^(.*):443$ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^/index.php$ [NC]
RewriteRule ^(.*)index\.php$ https://%1/$1 [L,R=301]

但它只适用于地址:site.com/index.php到site.com我需要从所有包含index.php的地址重定向,例如site.com/categories/rings/index.php到site.com/categories/rings/谢谢!

8ljdwjyq

8ljdwjyq1#

您的RewriteCond规则是问题所在:

RewriteRule ^(.*/)?index\.php$ https://%{HTTP_HOST}/$1 [L,R=301]

如果你想保留端口RewriteCond,你可以使用这个:

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*/)?index\.php$ https://%{HTTP_HOST}/$1 [L,R=301]
slmsl1lt

slmsl1lt2#

我在laravel项目的.htaccess文件中使用了这个

# Redirect index.php to non index.php
RewriteRule ^(.+)/index.(php|html) /$1 [R=301,L]
RewriteRule ^/index.(php|html) / [R=301,L]

相关问题