Apache: Customizing error responses

Apache provides the possibility to customize the HTTP error codes returned to your clients. If you hate the default error messages that Apache displays or you simply want to fit those messages to your own needs, read on…

The easiest way to start is by simply adding the following lines to your httpd.conf configuration file:

Alias /error “/path/to/documentroot/custom_err”

<Directory “/path/to/documentroot/custom_err”>
AllowOverride None
Options IncludesNoExec
Order allow,deny
Allow from all
</Directory>

ErrorDocument 403 /error/http_err_403.html
ErrorDocument 404 /error/http_err_404.html

Now go to your document root directory (see DocumentRoot directive in your httpd.conf) and make a directory called custom_err:

cd /path/to/documentroot
mkdir custom_err
cd custom_err

Now create the HTML files that would display custom error messages. Here goes a sample:

<html>
<head>
<title>HTTP ERROR 404</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″>
</head>
<body>
<center>
<h3>Ummm… Where are you trying to go?</h3>
<h4>Try <a href=”http://www.karkomaonline.com”>here</a></h4>
</center>
</body>
</html>

Finally restart the Apache daemon and point your browser to a nonexistent page… Et voila!

You can do more sophisticated things such as creating scripts to handle errors, redirections to other sites, etc… but this is your homework for today (see references below).

References:

Leave a Reply

You must be logged in to post a comment.