Apache RewriteRule问题 - 与服务器相比本地的不同行为

时间:2013-06-11 02:40:48

标签: apache mod-rewrite

我有一些非常奇怪的问题,一个简单的RewriteRule在本地工作,但当部署到服务器时,我的文本有500个错误:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

以下是我正在使用的代码:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/(foo|bar|baz)/?
    RewriteCond %{REQUEST_URI} !^/410/index.php$
    RewriteRule ^.*$ /410/index.php? [L]
</IfModule>

我想要的是/foo/bar/baz以外的任何内容,以显示位于/410/index.php的页面

是的,在服务器上安装/启用了mod_rewrite.c。

1 个答案:

答案 0 :(得分:0)

由于这是.htaccess文件,请尝试删除重写规则中“410”之前的斜杠。此外,如果你检查它是否是一个真正的文件,应该停止无限重定向回索引页。

我将猜测并说有一点点机会(我找不到相关的文档)你用?重写的请求字符串来刷新现有的查询字符串可能没有匹配。

RewriteEngine On
#check if it's a not a real file
RewriteCond %{REQUEST_FILENAME} !-f
#Check if the request doesn't start with foo, bar, or baz
RewriteCond %{REQUEST_URI} !^/(foo|bar|baz)
#Check if uri doesn't only contain the /410/index.php
RewriteCond %{REQUEST_URI} !^/410/index.php\??$
#rewrite the file
RewriteRule ^.*$ 410/index.php? [L]