When your site encounters a problem, it will display an error response. There are default error pages, however they aren’t special and you may want to have them match your website’s design or just make them look better. Here is how you can do that using .htaccess:The syntax is,

ErrorDocument <3-digit-code> <action>

Where can be:

  1. Text to be displayed. Wrap the text with quotes (“).
  2. An external URL to redirect to.
  3. A local URL to redirect to.

An example of all three (3) looks like this:

  1. Text to be displayed. Wrap the text with quotes (“).
ErrorDocument <3-digit-code> "Sorry, the script crashed."
  1. An external URL to redirect to.
ErrorDocument <3-digit-code> http://anotherdomain.com/
  1. A local URL to redirect to.
ErrorDocument <3-digit-code> /crashed.html

The local page does not need to be a HTML file.

For each case, you’ll need to replace with the three (3) digit error code.

Here is a table of common error codes:

3 Digit Code What it means
400 Bad Request
401 Authorization Required
402 Payment Required (not used yet)
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

The 400 error codes are client request errors, whereas the 500 error codes are server error codes.

The common error codes are: 400, 401, 403, 404, 405, 408, 414, 500, 502, and 504. But, of course you can choose which ever error code you want.