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
目录中有以下文件:

  • www
    [dir]
    • 测试
      [dir]
    • 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
目录,而且适用于任何目录。

好的问题似乎是
mod\u rewrite
mod\u dir
之间的冲突。可能的解决办法是:

  • 禁用
    mod_dir
  • :

    
    目录删除
    
  • 有关如何
    mod_rewrite
    mod_dir
    交互的更多详细信息,请参阅。为什么外部重定向是必要的


    相关链接


    将您的代码放入虚拟主机@riggsfully我刚刚尝试过,但没有任何区别。
    <IfModule mod_dir.c>
         DirectorySlash Off
    </IfModule>