My Web Hosting Manual


Home > .htaccess > Change Error Documents

Change Error Documents

This is probably the most used feature of .htaccess along with password protection. And indeed it's a needed and very useful feature, so here is how to use it.

First of all if you want to change the behavour of the errors in Apache, you need to know what they are. Here is a list:

Client Request Errors Server Errors
400 Bad Request
401 Authorization Required
402 Payment Required (not used)
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable (encoding)
407 Proxy Authentication Required
408 Request Timed Out
409 Conflicting Request
410 Gone
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

You will probably want to change the error document for error code 404 (page not found) and 500 (Internal Server Error).

A sample code would be:

ErrorDocument 404 /errors/notfound.html

This will show the page locaded in http://www.domain.com/errors/notfound.html

You may call the page anything you want. Just make sure the path and the name are correct in the .htaccess file.

Same applies to all other document errors like:

ErrorDocument 500 /errors/internalerror.html

A correct combination of codes would be:

ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/auth.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/servererror.html

You can also specify a full URL if you wish:

ErrorDocument 400 http://www.domain.com/errors/badrequest.html
ErrorDocument 401 http://www.domain.com/errors/auth.html
ErrorDocument 403 http://www.domain.com/errors/forbid.html
ErrorDocument 404 http://www.domain.com/errors/notfound.html
ErrorDocument 500 http://www.domain.com/errors/servererror.html

Simple as that.

Review It

You might also be interested in:






Top Hosting
  - Host Gator
  - Host Monster
  - Blue Host
  - Easy CGI
  - Lunar Pages
       
All content has been created by Juan Carlos Gorospe. These are my opinions and experiences.
Copyright © 2008, Juan Carlos Gorospe. All Rights Reserved.