Apache2 - 在" /index.php&#34之后的"路径" /查询时重定向;

时间:2016-09-21 09:30:50

标签: php apache .htaccess redirect mod-rewrite

我想用"路径"重定向每个请求。在" 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/管理员/界面等www.example.com(或www.example.com/index.php)。

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

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

1 个答案:

答案 0 :(得分:0)

这将仅匹配具有index.php加上斜杠的请求以及之后的任何内容:

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

您没有指定是否要对原始请求执行任何操作,因此我将其放在此处并进行重定向。 302是"找到",如果你想要"永久移动"则替换为301。