2013-04-25 113 views
1

为什么下面的Apache配置产生一个内部服务器错误: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

原因,为什么你的规则是失败的:你重写规则导致无限循环和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] 
+0

非常感谢,但我只是尝试这样做,我得到当我尝试所有这些网址时:http://127.0.0.1/MySite/about/en/,http://127.0.0.1/MySite/about/en,http://127.0.0.1/MySite/about/和http ://127.0.0.1/MySite/about。我应该在http://127.0.0.1/MySite/about.php获取该文件。注意 - .htaccess文件位于MySite目录中。 – 2013-04-25 21:23:06

+0

啊你没有提到你的问题中的MySite。我现在将编辑我的答案。 – anubhava 2013-04-25 21:30:58

+0

好吧,现在就试试吧。 – anubhava 2013-04-25 21:35:09