Custom Error Pages
This quick tutorial will show you how to create custom error documents using a .htaccess file.
The Documents
First of all you'll find that some free webhosts don't allow the use of .htaccess files, so you may need to check your hosts F.A.Q to see if that's the case, you shouldn't find any paid hosts that prevent you from using it.
The first thing to do is create the custom pages that you want to use, just as you would any normal page they can be .php, .htm, .html or whatever you like.
Below is a list of the common error codes, you may want to create a page for all of them or just some, it doesn't matter.
301 - Moved Permanently 302 - Moved Temporarily 400 - Bad Request 401 - Authorization Required 403 - Forbidden 404 - Not Found 405 - Method Not Allowed 408 - Request Timed Out 415 - Unsupported Media Type 500 - Internal Server Error 501 - Not Implemetned 502 - Bad Gateway 503 - Service Unavailable 504 - Gateway Timeout 504 - HTTP Version Not Supported
Some of these you'll never come across, the only ones i have pages for are 400, 401, 403, 404 & 500
Once you've created your pages, upload them to your webspace anywhere you like, it makes things easier to manage if you give them their own directory e.g /error_docs/ next we need to create the .htaccess file.
Before going any further you might find that you already have a .htaccess file in your main/root directory depending on any scripts you might have already installed or how the user accounts on your server are configured. If you do, you can simply add the code from below into the existing one.
The .htaccess File
Insert the following into a new file (or your existing .htaccess file) as an example lets assume you made a custom 404 page, named it 404.html and it's inside the /error_docs/ directory.
ErrorDocument 404 /error_docs/404.html
That's all you need to add to the file, no <html> tags or anything else, then just repeat the line and change the error numbers & page names accordingly for however many pages you created.
Now you need to save the file as .htaccess note the entire filename must be ".htaccess" (without the quotes) when you come to save it in notepad or a text editor you might find that an extension will get added to the end such as .txt or .html, the easiest way round this is when you go to file & save enter the name ".htaccess" with the quotes and it'll be saved as it should be without anything added to the end.
Upload the file to your main directory, and unless your FTP client is set to show hidden files you may find that once you upload it you can no longer see it, don't panic it's still there. Your custom error pages should now be displayed instead of the defaults, for example if you went to yoursite.com/some_made_up_page.html you would see your 404 error page.


