Different Ways to Use a 404 File-Not-Found Handler

1. Redirect to a File Not Found page
If a file doesn’t exist, you can redirect your users to a page saying so.

2. Redirect to the correct location of a file
If, for example, your server treats file names with case sensitivity turned on, then a request to abc.php and Abc.php will be different. If all your file names are in lowercase, then a request to Abc.php will return file not found. Fix this by catching the requested file name in your 404 handler, convert it to lowercase, and redirect to the file with all lowercase letters.

3. Redirect a missing page component
If, for example, another website is referencing an image from your website that no longer exists or which has been moved to a different folder, you can catch that request in your 404 handler and redirect to the correct location of the image, or any other component (javascript file, css file, etc).

4. Vanity / Short URLS
If you have a form at a long URL, e.g. http://www.mysite.com/web/forms/2011/05/19/index.php but you want to market a shorter URL to people like http://www.mysite.com/myevent, you can catch the path to the short URL in your 404 handler and redirect users to the long URL. This way, you don’t have to create actual folders and a file with a redirect in it.