提问人:Madara's Ghost 提问时间:9/30/2012 更新时间:9/30/2012 访问量:844
Mod_rewrite行为不符合预期
Mod_rewrite not Behaving as Expected
问:
我想创建一个重写规则,以便
www.example.com/whatever/here
将映射到
www.example.com/index.php/whatever/here
所以这是可用的。为此,我创建了以下规则集:$_SERVER['PATH_INFO']
RewriteEngine On
RewriteCond {%REQUEST_FILENAME} !-f
RewriteCond {%REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
只有这样才给了我一个 500 服务器错误。Apache 错误日志指出
[周日 9 月 30 日 17:23:08.758705 2012][核心:错误][PID 2584:TID 1704] [客户端::1:58591]AH00124:请求超出了 10 个内部的限制 由于可能的配置错误而重定向。用 'LimitInternalRecursion' 在必要时增加限制。用 “LogLevel debug”来获取回溯。
但我没有看到递归。当我尝试使用它时,让我们说一个查询:
RewriteRule ^(.*)$ index.php?route=$1
它按预期工作,但不可用。$_SERVER['PATH_INFO']
另外,在有人问之前,我想要,因为这样,我可以有这样的复杂路径:$_SERVER['PATH_INFO']
www.example.com/controller/action/data?more=data
如果我需要的话。
答:
1赞
Michael Berkowski
9/30/2012
#1
如果这是您的实际代码,则服务器环境变量在 中指定不正确。如果不是 500 个解析错误,这将导致忽略条件,并在导致循环的每个请求上进行重写。RewriteCond
RewriteEngine On
# The % goes outside the {}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# And add a [L] flag
RewriteRule ^(.*)$ index.php/$1 [L]
评论
0赞
Madara's Ghost
9/30/2012
完美,我知道这是一件愚蠢的事情,这很完美。非常感谢:)
上一个:访客点击计数器 - 建议的方法
下一个:合并多个 REGEX 语句
评论