【发布时间】:2016-08-24 22:56:31
【问题描述】:
我使用WampServer (Apache/PHP/MySQL),我的www 目录中有以下文件:
-
www[目录]-
test[目录] -
index.php[文件] -
.htaccess[文件]
-
我想将所有 URI 请求作为参数传递给index.php,而不会导致任何外部重定向(客户端浏览器中的位置更改)。所以我尝试使用以下规则:
RewriteRule ^(.*)$ index.php?path=$1 [nocase,qsappend,end]
这很好用,除非 URI 是 /test,在这种情况下,外部重定向会将位置更改为:
/test/?path=test
即使存在与 URI 同名的目录,如何确保外部重定向不会发生?
预期结果:
- 原始 URI 请求:
/test - 内部重定向:
index.php?path=test - 外部重定向:无
实际结果:
- 原始 URI 请求:
/test - 内部重定向:
index.php?path=test - 外部重定向:
/test/?path=test
理想的解决方案是通用的,不仅适用于test 目录,还适用于任何目录。
【问题讨论】:
-
将代码放入虚拟主机See here for how to
-
@RiggsFolly 我刚刚尝试过,但没有任何区别。
标签: apache mod-rewrite url-rewriting wampserver