【问题标题】:Rewrite rule exceeding internal redirect limit重写规则超出内部重定向限制
【发布时间】:2015-10-03 00:34:03
【问题描述】:

我的网站最多可以接受四个参数,因此我将以下内容添加到我的 .htaccess 中。

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?atr=$1&dir=$2&query=$3&lookup=$4 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?atr=$1&dir=$2&query=$3 [L]
RewriteRule ^([^/]*)/([^/]*)$ /index.php?atr=$1&dir=$2 [L]

RewriteRule ^([^/]*)$ /index.php?atr=$1 [L]

在我添加第五行以仅允许一个参数之前,一切正常。这会在 index.php 的所有实例中返回 500 个错误,错误如下:

Request exceeded the limit of 10 internal redirects

【问题讨论】:

  • 第五条规则是什么?
  • @hjpotter92 抱歉,我有点混淆了,我指的是第五行,第四条规则。

标签: .htaccess mod-rewrite url-rewriting friendly-url


【解决方案1】:

你的第四条规则会发生什么:

RewriteRule ^([^/]*)$ /index.php?atr=$1 [L]

这也匹配重定向/重写的 URL。所以,你会得到类似的东西:

http://host/index.php?atr=index.php%3Fatr=index.php%3Fatr=index.php%3Fatr=index.php%3Fatr=index.php

这是重定向循环。要解决此问题,只需使用否定匹配 index.php 本身的模式。

RewriteRule ^((?!index\.php)[^/]*)$ /index.php?atr=$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多