由于升级到 PHP 5.6,可能会有 .htaccess 重写循环而导致的 500 服务器错误


500 server error due to upgrading to PHP 5.6, .htaccess rewrite loop possibly?

我已经将PHP从5.5升级到5.6,突然间,我的使用url重写的网站出现了500服务器错误。我和网络主机谈过,他们说我的.htaccess会导致重写循环。不过很奇怪,因为我有相同的 .htaccess 文件并且它从未更改过。下面是我的.htaccess文件中的代码,有人知道我哪里弄错了?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www'.(.*) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !'.(js|css|gif|jpg|png|ico)$ [NC]
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule ^get/([0-9]+).gif$ /click/siggy/$1 [L]

我认为以下规则导致您的服务器上出现无限循环/500错误,因为目标路径正在重写自身:

RewriteCond %{REQUEST_URI} !'.(js|css|gif|jpg|png|ico)$ [NC]
RewriteRule ^(.*)$ /index.php [L]

上面的规则排除了js,css,gif..,并将任何其他文件重写为/index.php包括/index.php =>/index.php 。要解决此问题,您必须使用负重写 cond 排除目标路径/index.php:

 RewriteCond %{REQUEST_URI} !/index'.php$
RewriteCond %{REQUEST_URI} !'.(js|css|gif|jpg|png|ico)$ [NC]
RewriteRule ^(.*)$ index.php [QSA,L]