Apache 使用RewriteRule将任何请求重定向到PHP脚本,而无需外部重定向
我使用Apache 使用RewriteRule将任何请求重定向到PHP脚本,而无需外部重定向,apache,mod-rewrite,url-rewriting,wampserver,Apache,Mod Rewrite,Url Rewriting,Wampserver,我使用WampServer(Apache/PHP/MySQL),我的www目录中有以下文件: www[dir] 测试[dir] index.php[文件] .htaccess[文件] 我想将所有URI请求作为参数传递到index.php,而不引起任何外部重定向(在客户端浏览器中更改位置)。因此,我尝试使用以下规则: RewriteRule ^(.*)$ index.php?path=$1 [nocase,qsappend,end] 除了URI为/test,在这种情况下,外部重定向会将位
WampServer
(Apache/PHP/MySQL),我的www
目录中有以下文件:
[dir]www
[dir]测试
[文件]index.php
[文件].htaccess
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
目录,而且适用于任何目录。好的问题似乎是mod\u rewrite
和mod\u dir
之间的冲突。可能的解决办法是:
mod_dir
目录删除
mod_rewrite
和mod_dir
交互的更多详细信息,请参阅。为什么外部重定向是必要的
相关链接
<IfModule mod_dir.c>
DirectorySlash Off
</IfModule>