2014-01-07 49 views
1

我有以下.htacess文件删除PHP扩展和创建SEO友好的URL:500只在本地主机上的.htaccess内部错误 - 重定向循环

RewriteEngine On 

ErrorDocument 404 /404.php 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.php$ /$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*)$ index.php?page=$1 [L] 

这工作绝对没上托管时,我们的域,但是当我在本地主机服务器上进行本地测试时,会出现错误500,内部服务器错误。

在我的httpd.conf文件,重写模块未注释:

LoadModule rewrite_module modules/mod_rewrite.so 

Apache的错误日志指出:

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., referer: http://localhost:8888/Website/ 

任何想法?

回答

1

是的,这肯定是由于循环。

您的第一条规则是删除.php扩展名。然后404处理程序和第二条规则将所有文件发送到.php文件,因此循环将继续。

为了避免您可以使用这些规则:

RewriteEngine On 
RewriteBase /Website/ 

ErrorDocument 404 /Website/404.php 

RewriteCond %{THE_REQUEST} \s/+/Website/(.+?)\.php[\s?] [NC] 
RewriteRule^%1 [R=301,L,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*)$ index.php?page=$1 [L,QSA] 

注意,如果使用的%{THE_REQUEST}代替RewriteRuleTHE_REQUEST变量表示Apache从您的浏览器收到的原始请求,并且不会因其他规则的应用而更改。

+0

我很感谢帮助,但似乎有同样的问题。 –

+0

是否还有其他规则或任何其他.htaccess? – anubhava

+0

不,您在OP中发布的htaccess文件中看到的是我的.htaccess文件中的内容。它似乎很奇怪,它在我的域名上运行,但不在localhost上。 –