为什么以下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”部分,则将其添加为语言参数。
答案 0 :(得分: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]