How to Set Up A Custom 404 File Not Found Page
Let's do a quick survey: what do you usually do when you click a URL and encounter a "404 File Not Found" error? Do you:
1. Click on the BACK button of your browser and go somewhere else?
2. Try to back up one directory in the URL and try again?
3. Write to the webmaster of the site and the referring site to inform them of the situation?
If you are like most people, you'll simply click on the BACK button and try another place. The majority of people don't even know that there are any other alternatives.
You thus need to do something so that you do not lose this group of people who come to your site by following an old link or by typing your URL incorrectly.
Requirements for Customizing the 404 File Not Found Page
It is not possible to customize your 404 error page if your web host has not enabled this facility for your website. For example, at the time of this writing, if you host at Geocities or Tripod, you would not be able to customize your 404 Error Page.
If your web host has this facility, you will usually find mention of this somewhere in their documentation. In fact, if they mention somewhere that you can customize a file named ".htaccess", it probably means that you can also customize your 404 File Not Found error page.
The .htaccess file is what Apache web servers use to allow you to fine-tune your web server configurations at a directory level. Other types of web servers handle the customization of 404 error pages differently.
Step One: Creating/Modifying the .htaccess File
This step may not be necessary in all situations. Some web hosts already configure their web server so that it will look for a specific file in your web directory when a certain document cannot be found. If so, simply skip this step.
If your web server is not an Apache web server, you will have to find out from your web host what you need to do to enable the server to serve your customized file when a file cannot be found.
Otherwise, the first thing you need to do is to add the following line to a file named ".htaccess" (without the enclosing quotes and with the preceding period). In most instances, no such file will exist, and you can simply create one with a text editor (such as Notepad on Windows).
Code:
ErrorDocument 404 /notfound.html
You will of course need to put a notfound.html file in the main web directory for the above directive to work.
The "ErrorDocument 404" directive essentially tells the Apache web server that whenever it cannot find the file it needs in that directory and its subdirectories, it is to use the document specified in the URL that follows.
One .htaccess file in your main directory will do the trick for that directory and its subdirectories. However, if you want a certain subdirectory to show a different 404 File Not Found message, you can always place a .htaccess file into that directory. This will override any .htaccess files you have in the parent directories.
More information here: http://www.thesitewizard.com/archive/custom404.shtml
Bookmarks