由.htaccess文件导致的内部服务器错误

时间:2014-09-02 00:04:11

标签: php .htaccess url-rewriting

我使用下面的.htaccess代码将所有请求重定向到索引文件。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

它在某些远程服务器上运行良好,但在将其中一个使用它的站点移动到新服务器后,我收到内部服务器错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

导致此错误的原因是什么,以及如何解决此问题。

1 个答案:

答案 0 :(得分:2)

我的猜测是没有加载apache中的mod_rewrite模块。 检查你的apache配置!

要查看是否属于这种情况,并且为了避免将来出现错误,我总是将此类代码放入支票中。您也可以尝试一下,看看是否有效,如果它不再给您一个错误,那意味着mod_rewrite已关闭。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

您还可以使用以下方式进行检查:

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, send 404's
    # to a special page, so you can recognize the issue.

    ErrorDocument 404 /special_404_page.php
</IfModule>

另外,您可能想检查apache日志并查看它给出的错误!