Monday, October 15, 2007

Capturing Errors With Apache's Internal Handler

Howdy, Late nighters :)

Here's a tip if you're looking to capture any old error message with apache and want to do something creative with it.

The default server action is usually good enough, but, sometimes you might want to do something extra (like redirect to a script that does a little something extra on your backend, redirect to internal or external links that will show up in reports or just make your error messages fun ...Is that possible?)

The "ErrorDocument" keyword is used for exactly this purpose. Here are a few examples below (all scripts, sites, paths, etc, are purely made up and probaby don't reflect your server configuration)

The syntax is: ErrorDocument ErrorNumber Action(First is plain text, next two are internal redirects, last is external)
ErrorDocument 301 "You got an error 301. Awesome!"
ErrorDocument 301 /public_html/errors/error_301.html
ErrorDocument 301 /cgi-bin/someErrorHandlingProgram.pl
ErrorDocument 301 http://www.errrors.com/error301.html


If there's interest, there might be something to doing some real custom whiz-work in a perl/cgi script to really "handle" errors :P

, Mike