Apache2 -当"path"/ index.php"之后给出"path&qu


Apache2 - Redirect when "path"/query is given after "/index.php"

我想将每个请求在"index.php"之后的"路径"重定向到我的域,或者,如果不可能,直接到index.php,但我不知道这种情况下的RewriteRule/RewriteCond。

例如,我想重定向www.example.com/index.php/test, www.example.com/index.php/test/hello.php, www.example.com/index.php/test/admin/interface等到www.example.com(或www.example.com/index.php)。

我不想将任何其他文件或目录(如www.example.com/admin或www.example.com/interface/admin.php)重定向到我的index.php,只是URL中"/index.php"之后给出的任何"路径"。当然,我也不希望将www.example.com/index.php或www.example.com重定向到以重定向循环结束的自身。

有人知道解决方案(RewriteRule/RewriteCond)吗?

这将只匹配带有index.php +斜杠和后面任何内容的请求:

RewriteCond %{THE_REQUEST} /index.php/.*$
RewriteRule ^ index.php [R=302]

你没有指定你是否想对原始请求做任何事情,所以我在这里删除它,只做一个重定向。302是"found",如果你想"永久移动",用301代替。