我之前见过这个问题,但没有答案:.htaccess 规则删除 URL 末尾的 index.php
我遇到了与原始海报相同的问题。我的 Joomla 网站上的网址最后显示为 index.php。我希望所有以index.php结尾的网址都重定向到同一页面,末尾不带index.php。
示例:www.mysite.com/forum/index.php 应重定向至 www.mysite.com/forum
我已经尝试过这段代码
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
但它会将末尾带有index.php的所有网址重定向到我的网站主页
示例 www.mysite.com/forum/index.php 最终被重定向到 www.mysite.com
对此的任何帮助将不胜感激!
您可以使用此规则作为您的第一条规则:
RewriteCond %{THE_REQUEST} !/admin/ [NC]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
我遇到了类似的问题,但该代码对我不起作用,我改用了这个:
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]