.htaccess 边缘案例
我在 .htaccess 中使用这些规则和条件将它们转换
http://www.example.com/index.php/about/history
http://www.example.com/about/history/index.php
为
http://www.example.com/about/history
.htaccess
# ensure there is no /index.php in the address bar
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ $1 [R=301,L,NS]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(.*)\ HTTP/ [NC]
RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]
除非有一种情况,如果 URL 是
http://www.example.com/about/index.php/history/
它将导致重定向的无限循环。 现在我知道这可能很罕见,但如果可能的话,我希望它不要发生。 我如何更改我的规则以适应这种情况?
I am using these rules and conditions in .htaccess to turn these
http://www.example.com/index.php/about/history
http://www.example.com/about/history/index.php
into
http://www.example.com/about/history
.htaccess
# ensure there is no /index.php in the address bar
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ $1 [R=301,L,NS]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(.*)\ HTTP/ [NC]
RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]
Except there is a case where if the URL is
http://www.example.com/about/index.php/history/
It will result in an endless loop of redirecting. Now I know this is probably a rarity, but I'd like it not to happen if possible. How can I change my rules to accomodate this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你只是想删除index.php,无论它出现在哪里? 在这种情况下,您的解决方案过于复杂。 你可能想要这样的东西
这应该是唯一的规则,也不需要 RewriteCond
If I understand correctly you just want to remove index.php whereever it appears? In that case your solution is overly complex. You probably want something like
This should be the only rule, no need for the RewriteCond's as well