2/13/2008

Custom Error Pages with .htaccess

"404" - Custom Error Pages
How do I customize error messages for my site? You can customize error messages (404 Not Found, for example) by creating a file called .htaccess and including the appropriate entries. This file should be uploaded to your root directory (i.e., the "www" folder for your account).

Some of the most common messages are as follows:

Error in Client
400 Bad syntax
401 Unauthorized
402 Not Used (Payment Granted)
403 Forbidden
404 Not Found

Error in Server
500 Internal Error
501 Not Implemented
502 Overloaded
503 Gateway Timeout

You can customize error messages for your site as follows:
Create the HTML page you want to use as your error message and upload it to your web directory (/home/username/domain-www). Next, edit your .htaccess file (or create one using a text editor) and add lines which specify the substitution.

Here are three examples of specifying error documents which will be called for a given error condition (note that you can use relative "thisfile.html" or absolute addressing "http://www.yourdomain.com/thisfile.html"):

ErrorDocument 401 http://yourdomain.com/nopassword.html
ErrorDocument 403 /forbidden.html
ErrorDocument 404 http://www.yourdomain.com/nofile.html

Please note that Windows will not allow you to create a file called .htaccess. It will be necessary to create this file using another name and then rename it once you have uploaded it to your site.

If you use FrontPage to publish your web page(s), custom .htaccess files cannot be used.

No comments:

Live Page Popularity