且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从网站 URL 中删除 index.php

更新时间:2023-02-23 12:58:37

试试这个:

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

您没有处理的是所有请求都可以重写,当您进行重写时,它会生成一个子请求——它也可以重写.因此,您最终将/articles 重写为/index.php/articles,然后在该问题的子请求中,将/index.php/articles 重写为/articles 并为 301 重定向生成一个新请求,如此反复.添加 NS 标志将使此规则不会对子请求进行操作,我认为这应该可以解决您的问题,除非您还在/articles ->/index.php/articles 重写上执行 301(但这会很疯狂).

What you're not processing is that all requests are subject to rewriting, and when you do a rewrite it generate a subrequest -- which is also subject to rewriting. So you wind up rewriting /articles to /index.php/articles, then in the subrequest that that issue, you rewrite /index.php/articles to /articles and generate a new request for the 301 redirect, on and on. Adding the NS flag will make this rule not operate on subrequests, which I think should fix your problem, unless you're also doing a 301 on the /articles -> /index.php/articles rewrite (but that would be madness).