Before you start with this tutorial, please check if your host offers a way to add custom error pages through a user panel or some other interface. If you have that option you can stop reading right here! :-)
First make the error pages. They are just standard html pages, but the links (to images etc.) must be absolute and look like this: http://www.myDomain/myImages/theImage.gif
When the error pages are uploaded you need to create an .htaccess file. Here is some very important information on how to create and upload an .htaccess file:
So, what should go into the .htaccess file? Here is an example:
ErrorDocument 404 /errors/notfound.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 500 /errors/internalerror.html
ErrorDocument 403 /errors/forbid.html
You can name the error pages whatever you like , just make sure that you connect the right document to the right error number, and that you don't use any special characters or spaces in the paths and file names.
In the example above all the error pages are located in the folder "errors", the paths must be absolute (starting with the root "/").
When you created the .htaccess file you save it, upload it and change the file name like I mentioned earlier.
The .htaccess file must be located in your root folder, since it only affects the folder where it's located and all sub folders. If you place the file further down the file structure the higher levels will not get your custom error pages.
You don't need to create custom pages for all errors, if you just want a 404 the server will use the default pages for all other errors.
The errors that you might want to cover are:
- 400 - Bad request
- 401 - Authorization Required
- 403 - Forbidden
- 404 - Not Found
- 500 - Internal Server Error
That's it!
- michael ahgren
|