【问题标题】:Simple redirect apache infinite loop简单的重定向 apache 无限循环
【发布时间】:2015-12-07 09:20:02
【问题描述】:

我在 windows 7 下使用 xampp。我已将 .htaccess 放在 %XAMPP_ROOT%/htdocs 中。 .htaccess 包含以下行:

Redirect / http://localhost/test.php/

在浏览器的地址字段中输入http://localhost 后,我遇到了一个无限循环错误 http://localhost/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/test.php/。但我预计我会被重定向到http://localhost/test.php/

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    您应该使用RedirectMatch 来避免使用正则表达式的这种情况:

    RedirectMatch ^/?$ http://localhost/test.php/
    

    【讨论】:

      【解决方案2】:

      Redirect directive 匹配以提供的 URL 开头的所有内容:

      那么任何以 URL-Path 开头的请求都会在目标 URL 的位置向客户端返回一个重定向请求。

      这意味着/ 将匹配每个请求,包括/test.php/。此外,斜杠之后的所有内容都将附加到目标 URL。这就是您获得递归 URL 的原因。

      您必须使用RedirectMatch 仅匹配根路径/

      RedirectMatch ^/?$ http://localhost/test.php/
      

      感谢anubhava 提供的解决方案。

      【讨论】:

        猜你喜欢
        • 2019-04-01
        • 2011-03-11
        • 2021-04-15
        • 2014-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-25
        • 2012-06-08
        相关资源
        最近更新 更多