Site Fuse! programming, design, hosting, promotion and advertising tips for webmasters
Design    Programming    Hosting    Classifieds

Custom error pages with .htaccess


Important: The following is a text only archive!
For full features; Go to Custom error pages with .htaccess

posted by 2Guns Create a new file called .htaccess. You will probably have a hard time creating a filename like this if you're in Windows enviroment, so I suggest you to create a file with the name htaccess.txt, you can then rename it to .htaccess once you upload it to your server with the FTP software...

400 - Bad request
401 - Authorization Required
403 - Forbidden
404 - Not found
500 - Internal Server Error

are the most common errors. By adding a couple of lines to your .htaccess file you can display a page or redirect the user to a different URL when an error occurs.

Usage:

ErrorDocument error_code file or URL to display

A couple of examples;

ErrorDocument 404 http://www.yourdomain.com
This will redirect the user to yourdomain.com when a document cannot be found.

ErrorDocument 500 /blah.html
This will display the file blah.html when an internal server occurs. Remember, you need to create and upload a file with the name blah.html to the root directory of your site.

If you want to place your error pages other than the root directory;

ErrorDocument 404 /errors/page_404.html
ErrorDocument 500 /errors/page_500.html
Here's what I use on most of my sites;

ErrorDocument 400 http://www.domain.com
ErrorDocument 401 http://www.domain.com
ErrorDocument 403 http://www.domain.com
ErrorDocument 404 http://www.domain.com
ErrorDocument 500 /errors/page_500.html