簡體   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