【发布时间】:2017-01-29 11:23:09
【问题描述】:
我想在“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,只是任何“路径”在 URL 中的“/index.php”之后给出。当然,我也不想将 www.example.com/index.php 或 www.example.com 重定向到以重定向循环结尾的自身。
有人知道解决方案(RewriteRule/RewriteCond)吗?
【问题讨论】:
-
RewriteEngine on RewriteRule ^.+$ /index.php [L]这会将每个查询重定向到根目录的 index.php -
感谢您的回答,但我不想将每个不存在的文件或目录重定向到 index.php (RewriteCond %{"REQUEST_FILENAME} !-f" 或 "RewriteCond %{ REQUEST_FILENAME"} !-d),因为我有一个自定义错误 404 页面。我只想将 在 URL 中“/index.php”之后给出的任何“路径”/查询重定向到 index.php,而不遵循路径/查询,而不是任何路径/查询或任何不存在一般的路径或文件。
标签: php apache .htaccess redirect mod-rewrite