Creating Custom Error Messages With .htaccess

Most servers default to the “standard” Apache error message pages for most common browser errors. If you want to develop your own error pages, you’ll need to define those pages in a file named .htaccess, which you upload into your main www directory. The custom error pages that you develop also need to be uploaded into your www directory.

401 Authorization Required

This is the page that’s displayed when a user attempts to enter a password-protected directory with an incorrect login and password. To define your custom error page as authorization.html, add the following line to your .htaccess file:

ErrorDocument 401 /authorization.html

403 Access Forbidden

This is the page that’s displayed when a user attempts to enter non-web-enabled directory (e.g., this page will be displayed when the user attempts to enter a directory that does not have an index page defined. They’ll also get this page if your account is disabled.) To define your custom error page as access.html, add the following line to your .htaccess file:

ErrorDocument 403 /access.html

500 Internal Server Error

This is the page your visitors see when there is an error processing a CGI script. To define your error page as ise.html, add this line to your .htaccess file:

ErrorDocument 500 /error.html

Note: If the full URL of your site is http://www.yourdomain.com, /error.html means its location is http://www.yourdomain.com/error.html.

Error Codes

There are a number of possible errors that a visitor might encounter. Each of these errors is associated with a numeric code (e.g., 401, 403, 500 as described above.) You can develop your own error document for any of these codes:

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

We also have a post about custom 404 pages.