繁体   English   中英

httpd.conf中的ErrorDocument无法正常工作

[英]ErrorDocument in httpd.conf not working

我想为403使用自定义错误文件,但是apache似乎忽略了指令ErrorDocument ,只是给了我默认错误文件。 这是我的httpd.conf的开始

ServerRoot "C:/xampp/apache"

Listen 80

ErrorDocument 403 "/403.html" 
ErrorDocument 404 "/403.html"

我只是添加了404以查看它是否有效,但没有成功。 403.html文件存在于C:\\xampp\\apache\\403.html

我尝试将ErrorDocument指令在配置文件中进一步下移,其中描述ErrorDocument指令的注释开始,但结果相同。

我正在测试的文件夹中的任何.htaccess文件中都没有ErrorDocument指令。

你能告诉我为什么Apache不理我吗?

编辑

只是为了确保我会提及我对此进行测试的方式。 我在C:\\xampp\\htdocs有一个.htaccess文件,其内容如下

Order deny,allow
Allow from 127.0.0.1
Allow from ::1
Deny from all

其目的是拒绝访问所有未明确允许的子文件夹和文件,然后我只是向公共IP发送请求以拒绝访问。

如果发生任何错误,首先要查找的是apache安装的logs/error.loglogs/access.log日志文件。

正如http://httpd.apache.org/docs/2.2/mod/core.html#errordocument上的文档所述,该指令是相对于当前主机配置的DocumentRoot的。 您没有使用默认的Apache HTTPD,而是使用了预配置的Apachefriends XAMPP,它具有一些特殊性,例如XAMPP随附的标准httpd.conf通过以下方式引用ErrorDocument

# Multi-language error messages
Include conf/extra/httpd-multilang-errordoc.conf

在默认的httpd.conf您的DocumentRootC:\\apache\\htdocs因此,通过在httpd.conf上述更改(即ErrorDocument 403 "/403.html" ),您必须将这些文件放入C:\\xampp\\htdocs\\403.html

顺便说一句,通常最好将您的自定义配置分开,方法是在httpd.conf添加一个Include conf/my-custom.conf并在其中添加您的配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM