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!

Alternate Step One: Using .htaccess to Add your 404 Error Page

If you’d rather not muck with the innards of your httpd.conf file, there’s a sensible and less overwhelming alternative solution, at least if you’re using the Apache web server. Instead, create a file in your Web site’s home directory called .htaccess (yes, that’s a dot or period as the first letter. It’s very important!)

You can accomplish this if you have direct edit capabilities on your server, or you can create a file with the correct name on your PC or Macintosh and upload it to the server. Regardless, the content of the file should be exactly:

ErrorDocument 404 /404-error-page.html

In this instance, you’re defining the name of your error page to be exactly 404-error-page.html and that it’s going to live at the topmost directory of your Web site. If you’d prefer a different name, then modify the contents of this file appropriately.

If you use FTP to upload this file to your server, make sure that you transfer it in “text” or “ascii” mode so that it’s properly parsed by the server.

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.

Step Four: Testing

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.