How To Use The .htaccess File To Display Custom Error Pages
Custom error pages are frequently used to provide additional information to visitors and to maintain the look and feel of your Web site. Some of the more common customized error pages include:
- 206 Partial content
- 301 Document moved permanently
- 302 Document found elsewhere
- 400 Bad request
- 401 Authorization required
- 403 Access forbidden
- 404 Document not found
- 408 Request timeout
- 500 Internal server error
- 501 Request type not supported
When creating the custom error page, consider including the following:
- Main navigation links
- Brief explanation of error
- Contact information, e.g. e-mail link to the Webmaster
- Site map or search function for the rest of your Web site
- Hyperlink to the page if it’s been moved
Save the custom error pages to your root directory. Once you’ve created your custom error pages, the .htaccess file is used to activate them:
Access the main root directory of your Web site and look for the .htaccess file
If the file exists you will need to edit it
If the file does not exist you will need to create it using a text software such as NotePad – the file name should be only .htaccess, if NotePad adds an additional extension to the name, you will need to remove it
Add / edit the following line:
ErrorDocument 404 /error404.html
After ErrorDocument specify the error code, followed by a space, and then the path and filename of the .html customized error file you would like to be displayed when the specified error is generated.
Using some of the error codes above your .htaccess file would look like this:
ErrorDocument 206 /error206.html
ErrorDocument 301 /error301.html
ErrorDocument 400 /error400.html
ErrorDocument 403 /error403.html
ErrorDocument 500 /error500.html
The .htaccess file should be saved in the domain root directory where the customized error pages are located
Note
- .htaccess files must be uploaded in ASCII mode not binary mode, and the permissions need to be set at 644 (rw-r--r--).
- .htaccess files affect the directory they are placed in and all sub-directories.





