Custom 404 not found and so on…

December 18, 2007

We are familiar with 404 not found error. it happens when the requested file is not found. But we can customize this error message.

There are some other apache error codes. We can categorize few of them as follows

  • Client Request Errors
    • 400 – Bad Syntax
    • 401 – Authorization Required
    • 404 – Not Found – most common
  • Server Request Errors
    • 500 – Internal Server Error

To customize the error message we need to follow the following steps

  • First, create the HTML page (e404.php) that we want to use as your error message and save it into the home directory
  • Add the following line in the .htaccess file
    • ErrorDocument 404 /e404.php
  • These two files are stored in the home directory (/htdocs/e404.php, /htdocs/.htaccess)
  • Now lets test it . From the browser address bar request (http://localhost/invalidScriptName) for any script that are not eixsts physically and the custom messages will be shown that are used in the e404.php

Thanks
$haymoL
eXploRinG Apache