【问题标题】:htaccess rewrite of directory to variable fails on localhosthtaccess 将目录重写为变量在 localhost 上失败
【发布时间】:2011-11-16 16:44:35
【问题描述】:

让我们以this question 之类的为例。所以,我正在寻找重写:

http://www.example.com/test

http://www.example.com/page.php?v=test

与:

RewriteRule ^(.*)$ page.php?v=$1 [L]

这会将我带到页面http://www.example.com/test/?v=test

为什么它不在http://www.example.com/test 上没有尾部斜杠和查询字符串。

PS:我在 Windows 上使用 WampServer

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting query-string


    【解决方案1】:

    RewriteRule 中不要放/ 和开头!

    RewriteRule ^(.*)$ page.php?id=$1 [L]
    

    【讨论】:

    • 感谢您的评论,但这并没有解决问题。删除斜线并没有改变结果。
    • 那个整个.htaccess加上一个RewriteEngine On。我还应该注意我正在使用 WampServer
    【解决方案2】:

    如果test 是服务器上的现有目录,则会出现问题。然后 Apache 使用 DirectorySlash Directive 通过添加尾部斜杠来“修复”指向目录的 URL。

    我在这里回答我自己的问题,但解决方案(如上面的链接所述)是将DirectorySlash Off 添加到 .htaccess

    【讨论】:

      猜你喜欢
      • 2014-06-10
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      相关资源
      最近更新 更多