Custom Error Pages with .htaccess Files

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:

Common Errors
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: ,

1 Response to “Custom Error Pages with .htaccess Files”

  • Sam Richards July 22, 2010 at 3:44 pm

    I have a problem with exiting .htaccess file. I used rewrite url code to convert /index.php or others to same url. I do his for every site and it works but when I try doing it to a new website a problem occurred. The site opens fine in Internet Explorer but Mozilla doesn’t allow it to open. It says the url is redirecting to unknown place.

Trackbacks

Trackback URL:

Leave a Reply to Sam Richards

Want us to work on your project?

Contact us today for a quote. Click here to submit details regarding your project.

If you are making a general inquiry, send an email to info@velvetblues.com

Go Daddy Deal of the Week: Cheap .COM Domains! Offer expires soon!