If you're new here, you may want to subscribe to my RSS feed. So that you can read the latest updates about Web2.0 tools, Making Money Online, Tips in SEO, Ajax and many more. Thanks for visiting ProgramimiCOM!

First off, it’s not as hard as you think! These directions are for the popular Apache web browser but odds are pretty darn good that’s what server you have anyway! if not, then a quick google of “adding a 404 error page” coupled with the name of your web server will probably do the trick!

Step One: Modify the httpd.conf file

The first step, and perhaps the most challenging, is to find your Web server configuration file - often called httpd.conf - and find the block of statements that define the location and behavior of your particular site. This file is commonly found at /etc/httpd/httpd.conf, /usr/local/www/conf/httpd.conf or a similar location: if you can’t find it, ask your system administrator. On a typical server configuration, it might look like this:

<VirtualHost www.example.com>
ServerName www.example.com
ServerAdmin admin@example.com
DocumentRoot /usr/local/www/example.com
ErrorLog logs/example/error_log
TransferLog logs/example/access_log
</VirtualHost>

Your server might have dozens (or more) of these VirtualHost blocks in the configuration file: make sure you find the one for your exact domain name before you make any modifications. Now that you’ve found this section, you need to add an ErrorDocument handler that specifies the exact numeric code and the name of the file to serve up (or CGI script to run) when that error is encountered. Here’s how that might well look:

ErrorDocument 404 /errordoc-404.shtml

In this case, when error 404 is encountered - page or file not found - then the file errordoc-404.shtml will be served up (and notice that you can have server-side includes (SSI) in error documents if you’d like. One trick, though, is to remember that error pages can pop up anywhere in your site heirarchy, so make sure all your graphic references, links to other areas on the site, etc, are absolute references, that they start with ‘/’ or, in extreme cases, ‘http:’.

Note: There’s another way you can hook a custom 404 error page into your site too, using a .htaccess file, as explained in How to use .htaccess to create a custom 404 error page .

Step Two: Create the 404 Error Page

There are lots of different error 404 pages you can create, ranging from the succinct and dry to the peculiar, to the witty, to the super-helpful (for example, you can easily add a google search for only pages from your site to your 404 error page ).

Whichever path you choose, you’ll find people appreciate if you at least offer a link to your home page and some method whereby they can contact you if they are insistent that certain material should be present but isn’t.

Also, most people agree that not insulting them is a good strategy, but, perhaps surprisingly, this varies and there are definitely some 404 error pages out there that are quite blunt.

It depends on the style of your site, your sense of humor, and whether you want to err on the side of “useful” or on the side of “amusing”.

Step Three: Restart the Web Server

To get the change to the configuration file accepted, you’ll probably need to restart or otherwise nudge your Apache Web server so it knows that you’ve added a custom 404 error page (otherwise it’ll continue to blithly serve up the generic error page instead).

There are a couple of basic commands to accomplish this task:

  1. apachectl is most common,
  2. or you might need to revert to a custom script like restart_apache,
  3. or tools like Webmin have a restart option,
  4. or, if this all seems like too much work, just ask a sysadmin to restart the server.

Regardless of which you choose, it’s always a good idea to also check the log files for the Web server to ensure that everything was accepted and parsed without any errors. On a typical Linux/Unix configuration, the log file would be at

/var/log/messages

because Apache (almost always) is configured to use the standard syslog mechanism.

Once that happens, type in a URL that you know isn’t present on your site and see what happens! If everything is correct, you should see the new 404 error page pop up.

If it doesn’t work, go back to your httpd.conf file, identify where errors are logged (probably an entry ErrorLog) then look in that file to see what’s wrong.

Most likely you have a naming error where it’s called one thing in the configuration file but something else on the actual server.

If everything is working fine, try a second 404 error by requesting a page that’s a few subdirectories into the site, so while for your first test you may have used something like http://www.example.com/badpage this time try something more like http://www.example.com/some/subdir/badpage

If all the graphics are displayed properly and the links to elsewhere on your site are all correct, congratulations! You’ve done it! You’re now the proud owner of a custom 404 error page.

If not, step through this tutorial again, keeping an eye on the error log file, and you should have this figured out in no time.