ErrorDocument
The ErrorDocument
directive lets you specify what
happens when a client asks for a nonexistent document.
ErrorDocument error-code "document" (in Apache v2)
Server config, virtual host, directory, .htaccess
In the event of a problem or error, Apache can be configured to do one of four things:
Output a simple hardcoded error message.
Output a customized message.
Redirect to a local URL to handle the problem/error.
Redirect to an external URL to handle the problem/error.
The first option is the default, whereas options 2 through 4 are
configured using the ErrorDocument
directive,
which is followed by the HTTP response code and a message or URL.
Messages in this context begin with a double quotation mark
("
), which does not form part of the message
itself. Apache will sometimes offer additional information regarding
the problem or error.
URLs can be local URLs beginning with a slash (/ ) or full URLs that the client can resolve. For example:
ErrorDocument 500 http://foo.example.com/cgi-bin/tester ErrorDocument 404 /cgi-bin/bad_urls.pl ErrorDocument 401 /subscription_info.html ErrorDocument 403 "Sorry can't allow you access today"
Note that when you specify an ErrorDocument
that
points to a remote URL (i.e., anything with a method such as
“http” in front of it), Apache will
send a redirect to the client to tell it where to find the document,
even if the document ends up being on the same server. This has
several implications, the most important being that if you use an
ErrorDocument ...
Get Apache: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.