mod_rewrite:由于可能的配置错误,请求超出了10个内部重定向的限制

时间:2018-06-02 03:52:23

标签: apache mod-rewrite

我正在Linux上运行Apache 2.4和PHP 5.6并注意到以下错误当用户访问不存在该文件或direcrtory(例如:/test/1.asp或/ aa /)时此网站

Broswer显示:

bool found = false;

Apache错误日志:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@xxx.edu to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

.htaccess文件:

[core:error] [pid 12843] [client 202.xxx.xxx.xxx:64587] AH00124: 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.

重写规则:

Options -MultiViews
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(en|zh|ja|ko)/(.*)$ $2?lang=$1 [L,QSA]
RewriteRule ^(.*)$ $1?lang=zh [L,QSA]
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

默认:

http://www.example.com/en =>  http://www.example.com/index.php?lang=en 
http://www.example.com/jo =>  http://www.example.com/index.php?lang=jo
http://www.example.com/zh =>  http://www.example.com/index.php?lang=zh

在本网站中用户访问不存在文件或目录时应该返回404错误,而不是“内部服务器错误”。

如何解决?

感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用此

ErrorDocument 404 http://yourdomain.com/

您还有3个条件和3条规则。当3个条件成立时,将执行第一个条件。另外两个将无条件执行。我不确定这是你的意图。 每当[L] Flag通过新的迭代开始时,也可以在循环中思考。

<强>更新

在你的情况下,一个选项是(简化示例),然后从那里

RewriteEngine On

# check if language exists do redirect
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^/(en|zh|ja|ko)
RewriteRule  ^(.*)$ ?lang=$1 [L,QSA]

# if not found go to your 404 page
RewriteCond %{REQUEST_URI} !^/(en|zh|ja|ko)
RewriteRule ^(.*)$ /404.html [R=404,L]

另请参阅Apache mod_rewrite以了解mod_rewrite以及发生的事情。