Centos – apache: absolute ErrorDocument relative /var/www/

apache-2.2centoserrordocument

My apache VirtualHost contains an ErrorDocument directive:

<VirtualHost *:80>
  ServerName test
  DocumentRoot /var/www/html/test/
  ErrorDocument 404 /error/404.txt
</VirtualHost>

The file /var/www/html/test/error/404.txt does exist.

When trying to access a non-existing file, I get an error-in-a-error message from apache:

The requested URL /foo was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

The error log contains:

[error] File does not exist: /var/www/html/test/foo
[error] File does not exist: /var/www/error/404.txt

Why does apache make the error document path relative to /var/www (apache user's home dir) instead of relative to the virtual host's DocumentRoot, as described in the docs?

URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), …


This happens with Apache 2.2 on CentOS 6.7.

Best Answer

The reason for this error was the default configuration:

Alias /error/ "/var/www/error/"

Removing this line made it work.

Related Topic