1

I want to use custom error file for 403 but apache just seems to ignore the directive ErrorDocument and just gives me the default error document. Here's the beginning of my httpd.conf

ServerRoot "C:/xampp/apache"

Listen 80

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

I just added 404 to see if it would work, it didn't. The file 403.html exists inC:\xampp\apache\403.html

I tried moving the ErrorDocument directive further down in the configuration file, where comments describing ErrorDocument directive start but the result was the same.

I do not have ErrorDocument directives in any .htaccess files in folders that I'm testing.

Can you please tell me why apache is ignoring me?

EDIT

Just to be sure I will mention the way I'm testing this. I have a .htaccess file in C:\xampp\htdocs with the following contents

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

The purpose of which is to deny access to all subfolders and files that don't explicitly allow it, and then I'm just sending a request to my public IP to get access denied.

Community
  • 1
  • 1
php_nub_qq
  • 15,199
  • 21
  • 74
  • 144
  • Does it work when you use `ErrorDocument 403 http://localhost/403.html`. [This post may help](http://stackoverflow.com/questions/22976772/errordocument-404-404-php-is-not-working-in-htaccess-file-in-php) – slash Dec 29 '14 at 21:06

1 Answers1

1

The first place to look in case of any error are the logs/error.log and logs/access.log logfiles of your apache installation.

As the documentation at http://httpd.apache.org/docs/2.2/mod/core.html#errordocument states, this directive is relative to the DocumentRoot of your current host configuration. You are not using a default Apache HTTPD but instead the preconfigured Apachefriends XAMPP which has some specialties e.g. the standard httpd.conf coming with XAMPP references the ErrorDocuments via

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

In the default httpd.conf your DocumentRoot is C:\apache\htdocs so with your above mentioned changes (namely ErrorDocument 403 "/403.html") in your httpd.conf, you will have to place those files into C:\xampp\htdocs\403.html.

As an aside it is usually a good idea to separate your custom configuration by adding an Include conf/my-custom.conf to httpd.conf and adding your config in there.

  • I moved the file to `C:\xampp\htdocs\403.html` and restarted apache, just in case, but I'm still getting the default error document. Thanks for the suggestion for the separate configuration file, that's good advice! – php_nub_qq Dec 29 '14 at 21:22
  • After moving the file, did you verify that http://127.0.0.1/403.html returns your HTML file? The next step would be to set the `ErrorDocument` directive inside the `.htaccess` file. If this works fine, the problem is that your modified `ErrorDocument` directive inside your httpd.conf doesn't apply to the `htdocs` folder. – Alex Heusingfeld Jan 06 '15 at 23:22
  • It's very common that a directive is overwritten by another directive e.g. in a more specific scope or a position later in the loading phase. That's why I suggested to have a separate configuration file e.g. with a `` or a `` directive. That's where you usually put the config you have got in your `.htaccess` file now. What's the result when you put the `ErrorDocument` directive into your `.htacess`? – Alex Heusingfeld Jan 08 '15 at 08:47