Computing: Custom error pages
Introduction
This is a very common question asked across the web daily. A custom error page has many advantages, the most important being visitors will stay on your site. This short article will explain how to create custom error pages using an Apache servers .htaccess document.
Creating the .htaccess
The first thing to do is to create the .htaccess document that will tell the server where to find the error page that corresponds to the error. If you dont know how to create a .htaccess file then read on, else you can move on to the next section.
The best way I find to create a .htaccess file is to create a new plain text (.txt) file using notepad (or similar). Save the file as .htaccess.txt on your computer. When you upload the file to your web server you will need to remove the .txt extension thus creating your .htaccess file
The code
The following code is to be place into your .htaccess file:
ErrorDocument 404 /folder/file.htm
The syntax of this code is:
ErrorDocument [errorcode] [error_page_file]
The above example error code, 404, is for a page could not be found error. There are other error codes you can use:
- 400 - Bad request
- 401 - Authorization Required
- 403 - Forbidden directory
- 500 - Internal Server Error
You can change the file path to can file on your server. Once the .htaccess and your error page is uploaded, youre good to go with your spanking new custom error page!