Using HTML in .htaccess To Cover Pretty HTTP Errors
Recently I had a massive sort out of the domains, subdomains and other crap hosted here and found out that most of the time if a user got a 404 page, they got the default Apache 404 page, not a pretty error with a home link on it. So, I setup a .htaccess file in the top level folder of my webspace, so that it covered the entire of my website and everything on it without overriding any other .htaccess errors in child directories.
For instance, if you visit http://aelabs.net/thispageisnotfound/, you’ll get the same error page as you would get if you visited http://p.alanedwardes.com/notfoundeither/. I’ve also specified other general errors in the htaccess file, such as 403 erorrs, typically received when I haven’t set a root document, E.G. http://p.alanedwardes.com/.
It’s also a good way to make sure the Mint auto track PHP file is used on every single page here too, as i’ve added that into the file too. The end result looks something like this:
AddType application/x-httpd-php .html .htmphp_value auto_prepend_file /home/[username]/sites/mint/config/auto.php
ErrorDocument 400 "<style>body{font-family:'Lucida Sans Unicode', Garuda, Trebuchet MS, Arial, Tahoma;}</style><title>Bad Request</title><h1>Error 400 - Bad Request</h1><p>Your browser sent the server a request that it is not able to process.</p><p><a href="http://alanedwardes.com/">Home</a> | <a href="http://alanedwardes.com/contact/">Contact</a>
ErrorDocument 401 "<style>body{font-family:'Lucida Sans Unicode', Garuda, Trebuchet MS, Arial, Tahoma;}</style><title>Authorization required</title><h1>Error 401 - Authorization required</h1><p>You need authorization to access this resource.</p><p><a href="http://alanedwardes.com/">Home</a> | <a href="http://alanedwardes.com/contact/">Contact</a>
ErrorDocument 403 "<style>body{font-family:'Lucida Sans Unicode', Garuda, Trebuchet MS, Arial, Tahoma;}</style><title>Forbidden</title><h1>Error 403 - Forbidden</h1><p>You do not have permission to access this resource.</p><p><a href="http://alanedwardes.com/">Home</a> | <a href="http://alanedwardes.com/contact/">Contact</a>
ErrorDocument 404 "<style>body{font-family:'Lucida Sans Unicode', Garuda, Trebuchet MS, Arial, Tahoma;}</style><title>File Not Found</title><h1>Error 404 - Not found</h1><p>The document was not found on this server.</p><p><a href="http://alanedwardes.com/">Home</a> | <a href="http://alanedwardes.com/contact/">Contact</a>
ErrorDocument 500 "<style>body{font-family:'Lucida Sans Unicode', Garuda, Trebuchet MS, Arial, Tahoma;}</style><title>Internal Server Error</title><h1>Error 500 - Internal Server Error</h1><p>The server encountered a problem while processing your request.</p><p><a href="http://alanedwardes.com/">Home</a> | <a href="http://alanedwardes.com/contact/">Contact</a
More friendly errors that cover your entire website. Neat.


Leave a Comment
Make yourself heard