htaccess errordocument无法正常工作

时间:2013-08-17 21:21:51

标签: apache .htaccess http-status-code-404 errordocument

我的理解是要显示自定义错误页面,必须加上

ErrorDocument 404 /error/404.php

在.htaccess中

另外,

AllowOverride All
必须在httpd.conf文件中设置

。但是,现在它已设置为

AllowOverride None

如果我将None更改为All,然后重新启动服务器,当我故意在地址栏中输入乱码时,我会收到内部服务器错误500。我做错了什么?

文件中的其他内容

IndexIgnore *

接着是

RewriteEngine on

然后是重写规则。

RewriteEngine on是导致问题的原因 - 见下文。

1 个答案:

答案 0 :(得分:0)

简答:此错误表示您忘记启用rewrite模块,但与ErrorDocument无关。

如何解决?

确保您已启用rewrite模块。这可以通过执行以下操作之一来完成:

  1. 在Apache配置文件中取消注释LoadModule rewrite_module modules/mod_rewrite.so
  2. 以root身份运行a2enmod rewrite仅适用于基于Debian的系统)。
  3. 为什么在添加ErrorDocument后才出现此错误?

    AllowOverride设置为None,这意味着您的.htaccess将被完全忽略。稍后,您将其设置为All以启用.htaccess文件。

    但是,您忘记启用rewrite模块,但您尝试在.htaccess中使用它。这与ErrorDocument无关,只是巧合。您发布的以下错误清楚地表明了这一点:

      

    [Sat Aug 17 17:33:46 2013] [alert] [client 127.0.0.1] C:/Data/MyWeb/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration