Mod_rewrite不符合预期

时间:2012-09-30 15:30:03

标签: apache mod-rewrite

我想创建一个重写规则,以便

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错误日志表明

  

[Sun Sep 30 17:23:08.758705 2012] [核心:错误] [pid 2584:tid 1704]   [client :: 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 个答案:

答案 0 :(得分:1)

如果这是您的真实代码,则RewriteCond中的服务器环境变量指定不正确。如果不是平坦的500解析错误,这将导致条件被忽略,并且重写将在每个导致循环的请求上发生。

RewriteEngine On
# The % goes outside the {}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# And add a [L] flag
RewriteRule ^(.*)$ index.php/$1 [L]