Custom Error Pages – Why You Should Customize and How To Do It

No Comments » Written on February 7th, 2011 by
Categories: Building Websites
Custom Error Pages – Why You Should Customize and How To Do It

We've all landed on website error pages. Sometimes they don't say much more than 404 or 500, and other times they give us funny or useful information. Here's why you should make sure you customize your site's error pages (at least the 404 Not Found ones), and how to go about doing it.

Why You Should Always Customize Your Error Pages

There are several reasons why you should never let your visitors land on a default error page.

  1. The default pages offer no real information, confusing some visitors, and annoying most others.
  2. It's like inviting a guest into your home, only to let them land in a black hole with no way out.
  3. The bottom line is that you are effectively sending your users away, rather than helping them stay engaged with your site.

What Kind Of Information Should A Custom Error Page Contain?

By customizing your error pages, you can help rather than annoy your lost visitors, and entice them to stay on your site rather than kicking them out the door. Many users appreciate when a custom error page injects a little humor into the situation, as evidenced by the many lists of funniest 404 error pages found on the net. If you want to bring some humor into your custom page, that's fine, but it's not essential. What is essential is that you give your visitors some helpful information and guidance so they can find what they were looking for, such as:

  • A link to your HTML sitemap, if you have one.
  • A few links to important "starter pages" that a first time visitor might appreciate.
  • A few links to some of the site's most popular pages.
  • A search box.

Make sure your error page looks like the rest of the site, with the header, footer, sidebars, etc. in tact. The difference is that the body of the page contains the custom error information.

How To Create A Custom Error Page

Luckily it's very easy to create a custom error page.

Simply save the error page template you created, naming it something like error404.html, and then place it in your website's root directory (usually public_html).

Next, add the following line of code to your site's .htaccess file*. (Be sure to substitute your site's URL for "yourdomain.com", and change the name of the file if you named it anything other than error404.html).

ErrorDocument 404 /error404.html

That will take care of all 404 Not Found errors. If you want to create custom error pages for other types of errors, repeat the above steps, adjusting the file name and ErrorDocument statement appropriately. For example, if you wanted to create a custom error page to handle all 500 Internal Server errors, just name your custom error page something like error500.html and add this line to your .htaccess.

ErrorDocument 500 /error500.html

You can get a complete list of error codes here.

So go create your custom error pages and keep your visitors happy and on your site!

*Note: If you don't already have an .htaccess file, simply create the file in your favorite text editor, name it .htaccess (yes, exactly like that - make sure nothing is before the dot, and nothing is after htaccess. If you use Windows Notepad, that means you need to save it as ".htaccess" with the quotes to avoid having Notepad automatically add .txt to the end). Once you've created the file, place it your site's root directory. Also note that some ftp software or web host's file managers fail to show the .htaccess file even if it actually exists, because it treats it as a hidden file. Always choose the option in your ftp software or file manager to show hidden files so you don't accidentally overwrite your existing .htaccess file with a new one.

Tags: , , ,

Leave a Reply