Web Design and Development
Creating custom error pages with Linux Apache is a very simple task, whether or not your web host has an error page utility. Here’s how we developers do it.
First, you’ll need a program – such as Notepad or WordPad – with the ability to make simple text files.
Second, you’ll need to have a page or pages that you’d like to direct your users to upon encountering an error. While it is possible to use one error page, you might want to create unique error pages for each type of error that might be encountered. I’ve listed the most common errors, along with their 3-digit error codes, below:
400 – Bad Request
401 – Unauthorized
403 – Forbidden
404 – Not Found
500 – Internal Server Error
Your error pages can be in any format (HTML, HTML, ASP, PHP, etc…) and can be saved using any filename. Be sure that your pages offer some value to the users by describing the error and offering ways to find what they are looking for. (For example, take a look at our 404 error page by modifying the name of the article in the url.)
And now that your error pages are completed, it is now time to create an .htaccess file. Take a look at the code sample below, for a basic example of the typical structure of an .htaccess file.
ErrorDocument 400 /path/to/error/file
ErrorDocument 401 /path/to/error/file
ErrorDocument 403 /path/to/error/file
ErrorDocument 404 /path/to/error/file
ErrorDocument 500 /path/to/error/file
You will notice that you can specify a file name for each type of error you’d like to ‘catch’. As for the path, there are three different options: absolute, full, or relative. See the examples below:
File Path Options
Absolute – /home/username/errorfilename
Full – http://www.yourdomain.com/errorfilename
Relative – /errorfilename
Finally, to make your own .htaccess file, open WordPad or Notepad and create a new text document. Copy the code sample above and simply modify the path to reflect the location and filenames of your error documents. When done, save the file by typing in ".htaccess". Upload everything to your server, and you’re all done! Be sure to verify that your paths are correct by invoking errors.
Let us know if you have any questions by leaving a comment below.Tags: error pages, htaccess file