ErrorDocument directive

By on 05-Jan-2012 in Encounter

ErrorDocument directive

 

A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration.

The original purpose of .htaccess – reflected in its name – was to allow per-directory access control, by for example requiring a password to access the content. Nowadays however, the .htaccess files can override many other configuration settings including content type and character set, CGI handlers, etc.

These files are placed inside the web tree, and are able to override a subset of the server’s global configuration for that directory, and all sub-directories

Problem

[root@server ~]# cat /var/log/httpd/error_log

[Thu Jan 05 14:07:41 2012] [notice] cannot use a full URL in a 401 ErrorDocument directive — ignoring!

Naturally you want to fix anything in your error log so I went looking for a solution. In my case it turns out what was happening was in one of my .htaccess files I was giving a complete URL as the path to error documents, the fix was to change it to a relative path.

Solution

Which basically means I had something like;

ErrorDocument 401 http://www.mysite.com/401.php

And I had to change it to

ErrorDocument 401 /401.php

Unfortunately it doesn’t tell you much about the location of your .htaccess file and if you have several sites on a server hunting it down could be a bummer. I would suggest using find and grep commands to help narrow down your list of possibilities. I did something like this;

[root@server ~]# find -name ‘.htaccess’ -exec grep ErrorDocument {} \; -print

From inside the home directory and it returned all the .htaccess files with reference to ErrorDocument. A very quick fix but one that will keep my Error Log all the cleaner!

Submit a Comment