1

为什么以下 Apache 配置会产生内部服务器错误:

# Turn on the rewriting engine
RewriteEngine On

# Redirect "page/" and "page" to "page.php" . Also, redirect "page/en/" and "page/en" to "page.php?lang=en" .
RewriteRule ^(.+)/?([a-z]?)/?$ $1.php?lang=$2 [QSA,NC,L]

所以,基本上,我要做的就是在页面末尾添加“.php”,如果存在“/en”部分,则将其添加为语言参数。

4

1 回答 1

0

您的规则失败的原因:您的重写规则导致无限循环并且 Apache 抛出内部服务器错误(500),因为Request exceeded the limit of 10 internal redirects(默认)。

以下是您应该如何为此任务编写重写规则:

RewriteEngine On
RewriteBase /MySite/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)(?:/(.*?)/?)?$ $1.php?lang=$2 [L,NC,QSA]
于 2013-04-25T20:26:03.493 回答