.htaccess 边缘案例

发布于 2024-07-22 01:07:54 字数 865 浏览 8 评论 0原文

我在 .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/

它将导致重定向的无限循环。 现在我知道这可能很罕见,但如果可能的话,我希望它不要发生。 我如何更改我的规则以适应这种情况?

有关我的 .htaccess 的更多信息

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?

More info here about my .htaccess

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2024-07-29 01:07:54

如果我理解正确的话,你只是想删除index.php,无论它出现在哪里? 在这种情况下,您的解决方案过于复杂。 你可能想要这样的东西

RewriteRule ^(.*)index\.php/(.*)$ $1$2 [NS,NC,L,R=301]

这应该是唯一的规则,也不需要 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

RewriteRule ^(.*)index\.php/(.*)$ $1$2 [NS,NC,L,R=301]

This should be the only rule, no need for the RewriteCond's as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文