【发布时间】:2019-07-23 01:38:08
【问题描述】:
注意:我在 Stack Overflow 上发现了很多类似的问题,但没有一个能真正帮助我找出问题所在。导致此循环的原因可能有数百个。
我在example.com 上有一个名为user.php 的文件。我在 .htaccess 中编写了一个简单的重写规则,它从 URL 中删除了 .php 文件扩展名。
一切正常,除了在浏览器中打开 example.com/user/<anything-here> 时收到 500 错误。我实际上预计会出现 404 错误。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php
我在日志中也得到以下错误:
[...] 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. [...] r->uri = /user/foobar.php.php.php.php.php.php.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php.php.php.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php.php.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php.php [...] redirected from r->uri = /user/foobar.php.php.php [...] redirected from r->uri = /user/foobar.php.php [...] redirected from r->uri = /user/foobar.php [...] redirected from r->uri = /user/foobar
我尝试逐步重现问题,但没有成功:
- 条件:
-
/user/foobar→ 不是目录吗? → 没错,名为foobar的目录不存在,所以foobar不是目录 -
/user/foobar.php→ 是文件吗? → 错误,名为foobar.php的文件不存在,所以foobar.php不是文件
-
- 重写:
- 不重写,因为第二个条件为假; URL 保持不变 (
/user/foobar)。服务器应返回 404 错误。但是,我收到了 500 错误。
- 不重写,因为第二个条件为假; URL 保持不变 (
究竟出了什么问题,是什么导致了循环,为什么?
【问题讨论】:
-
@LawrenceCherone 这不是问题。路径
/user/foobar不包含.php,所以这不是原因。 (如果我错了,请纠正我。)
标签: apache .htaccess mod-rewrite url-rewriting