Iknow that! Here is the infomation about that error and how to handle it:
The web is all about usability, consistency and speed... well, that's what we'd like to think anyway. In this article John shows us how to stop those dreaded 404 errors from plaguing our Apach-based web sites. With a bit of PHP and a htaccess file or two, your site will be free of 404's forever!The web is all about usability, consistency and speed… well, that's what we'd like to think anyway. Unfortunately the web isn't a perfect haven for anyone, and if you run your own web site, then there's many a way that you can do your part to help make the web a more useable and consistent information/communication medium.
In this article I'm going to show you how you can use one feature of Apache to stop those dreaded "404 File Not Found" errors from plaguing your web site. 404 errors are one of the top reasons why visitors leave a web site, and with a bit of PHP and htaccess, your site will be free of 404's forever.
To implement the technique described in this article you should have access to a web server running Apache and PHP version 4.1 or above. The web server can be either a Windows NT/2000 server or a Unix/Linux server, such as RedHat or Mandrake.
Apache is a very configurable web server, and it depicts a web site as a hierarchically structured set of files and directories. These directories are organized with parent-child relationships, like this:
Apache also supports configuration files knows as htaccess files. These files can be used to set various file/directory permissions, redirection attributes, and block users coming from a specific IP address, etc. Htaccess files are created with the filename ".htaccess" (notice the dot at the beginning of the filename) and can reside in any directory that an Apache server can process.
Because of the way Apache works, if I had an htaccess file saved in a directory called home and this directory also contained several sub-directories, then each sub-directory would be influenced by the htaccess file in the home directory as well.
Think of a situation in which you might want to password protect several directories on your web site; your web site may be structured with one main root directory and 23 sub-directories. By simply placing a specially designed htaccess file in the root directory, all 23 sub-directories are automatically protected as well. This is a great time-saver, because usually if you're modifying the attributes of one directory, then there's a good chance that you'd like the attributes of all of its sub-directories affected by affected as well.
Hopefully you now understand the benefits of Apache thinking in terms of a hierarchy. We can use this hierarchical structure to our benefit by creating a htaccess file that can trap 404 errors and redirect the user to the appropriate page or perform some specific action depending on the URL that the visitor typed in. Let's do that now.
Create a new file on your local machine and call it ".htaccess". If you're creating the file in notepad then make sure that you enclose the file name in double quotes as I have above otherwise it will be suffixed with a .txt extension, which will stop Apache recognising the htaccess file.
Apache has several re-write commands that can be used to overwrite Apaches default behaviour for several different events. To trap 404 errors, we re-write the ErrorDocument method. Place the following line into your htaccess file and save it:
ErrorDocument 404 404err.php
Believe it or not, that's the only line that we have to put in our htaccess file. The ErrorDocument keyword tells Apache that we're declaring a re-write for an error. The 404 tells Apache the error number that we want to trap, and the 404err.php tells Apache the name of the file that it should call when a 404 error occurs. You can use any file you like, but 404err.php is self-describing, so we will stick with it for now.
[Note] You can use the ErrorDocument keyword to trap several types of errors, and not just 404's. Here's a list of errors that you might also like to trap:
400: Apache doesn't understand the request the user is trying to make.
401: The user has failed authentication through an htaccess login.
403: The user is trying to access a forbidden area on the server.
500: An internal server error has occurred.
501: The requested feature is not implemented on the server.
[End Note]
Once you've saved your htaccess file locally, upload/copy it to a directory on your web server. Before our error trapping will work, we need to create the file that will handle the 404 errors. Create a new file named 404err.php, enter the following code into it, and then upload it into the same directory that you placed the htacess file into: