[thelist] Apache: Fun with error docs + tip

Peter Lowe pgl at instinct.org
Fri Aug 1 22:27:16 CDT 2003


On Aug 02, Frank wrote:
> 
> I'm gapping out, and for some reason, the idea of re-doing my error pages 
> for my site seems to be fun right now. So I'm customising my 404 pages, as 
> well as my 500. Can someone tell me what the most frequently encountered 
> errors might be and how to cause them to occur on my own server to test it?
>
> 404 and 500 can be relatively frequent.
> 
> 404, request a page that doesn't exist.
> 500?
> Other?

401 - Authorisation needed
403 - Forbidden
503 - Service temporarily unavailable

Full list used by Apache in src/main/http_protocol.c.

> <tip type="Apache" author="Frank Marion">
> 
> Did you know that you can customize your Apache error docs? You can dress 
> your "404 Not Found" pages, to suite your site's look, for example. It's 
> easy (and fully explained in your httpd.conf doc, a plain text file that 
> you can edit with any text editor). Note, you'll need to restart Apache for 
> the changes to take effect.
> 
> From the comments in the conf file.

...

> ---
> 2) local redirects
>         ErrorDocument 404 /missing.html
>                 to redirect to local URL /missing.html
>         ErrorDocument 404 /cgi-bin/missing_handler.pl
>                 N.B.: You can redirect to a script or a document using 
> server-side-includes.

Useful variables to play with for internal redirects:

REDIRECT_ERROR_NOTES	- default Apache error message
REDIRECT_STATUS		- type of error
REDIRECT_URL		- address that caused the error

There's a bunch more - see here for a list:

	http://httpd.apache.org/docs/custom-error.html

> 3) external redirects
>         ErrorDocument 402 
>         http://some.other-server.com/subscription_info.html
>         N.B.: Many of the environment variables associated with the original
>         request will *not* be available to such a script.

This method can be very annoying if the page redirected to doesn't show
which address caused the error. I often open lots of pages at the same
time and go make a cup of coffee while they load; it's frustrating to
see "404 page not found" and not know which URL exactly is broken. 

> ---
> 
> I, for example have created the following at the root of my server:
> 
>         ErrorDocument 404 /err_docs/err_404.cfm
>         ErrorDocument 500 /err_docs/err_500.cfm
> 
> It's that easy.
> 
> </tip>

<tip type=Apache author="Peter Lowe">

You can use the ErrorDocument directive to create a "virtual site" with
only one page. Just use something like:

	ErrorDocument 404 /script.php

and use PATH_INFO or REQUEST_URI to figure out what content to serve.

This does mean that error logs aren't created properly for pages that
really don't exist though. One way to get round this is by setting an
environment variable and using CustomLog with "env = real404" or
something, but it's not exactly elegant.

(A slightly nicer way of making a site with only one file is by using
ForceType and symlinking to it from wherever, but you still have to
manage all the filenames etc.)

</tip>

 - Peter

-- 
The Czech Republic: Home of the world's finest beer.
Litres drunk by Czechs so far this year: 958,086,528.28

 - http://prague.tv/toys/beer/


More information about the thelist mailing list