【发布时间】:2011-08-16 15:21:00
【问题描述】:
我为此工作了 2 个小时,但最后我放弃了。
我有两个条件:
1.如果用户请求一个php文件重定向cms/index.php?request=$1
2. 如果用户请求不同于 php (png,css,jpg) 的内容重定向 cms/website/$1
第一条规则有效,但我无法应用第二条规则。当用户请求 /cms/style.css 时,Apache 重定向 cms/website/style.css 并再次重定向 cms/website/website/style.css 并循环。
我的htaccess文件是这样的:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*\.php) /cms/index.php?request=$1 [L]
RewriteRule (.*\.!(php)) /cms/website/$1 [R,L]
注意:我不确定最后一个正则表达式是否正确。它返回 500。error_log 输出为
"[Tue Aug 16 16:26:11 2011] [error] [client 127.0.0.1] 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."
【问题讨论】:
-
Apache 日志有很多反复试验,所以很难确定,但第二条规则看起来是无限的——如果它匹配的话。所有规则将在重定向 (
[R]) 后再次运行,因此/cms/website/$1将再次匹配规则,并再次转发到/cms/website/cms/website/$1等。 -
@robin,实际上RewriteLooping 说如果我使用 [R],它不能循环。但是,即使设置了这个选项,它也会循环。
标签: .htaccess