Friday, June 27, 2008

Simple HTTP error pages collection

This is collection of following HTTP error pages to show to user instead of regular black-white versions as you get from default Apache HTTP Server or some others.

Client Error 4xx
  • 400 — Bad Request
  • 401 — Unauthorized
  • 403 — Forbidden
  • 404 — Not Found
  • 405 — Method Not Allowed
  • 408 — Request Timeout
  • 410 — Gone
  • 411 — Length Required
  • 412 — Precondition Failed
  • 413 — Request Entity Too Large
  • 414 — Request-URI Too Long
  • 415 — Unsupported Media Type
Server Error 5xx
  • 500 — Internal Server Error
  • 501 — Not Implemented
  • 502 — Bad Gateway
  • 503 — Service Unavailable
You should know, that Apache has build-in support for multi language error pages and mine is not, english only (as for now). It may be important depending on project you are working on.

All you need to do is to replace following patterns:
1) replace your site link

<a href="http://your-site/" title="http://your-site/">Home page</a>

2) and your e-mail and name

<a href="mailto:your-name@your-site" title="Your Name">Web-admin</a>


Now, you need to configure your front-end.

Apache (at httpd.conf or external included in httpd.conf)

ErrorDocument 400 /http_errors/en/400.html
ErrorDocument 401 /http_errors/en/401.html
ErrorDocument 403 /http_errors/en/403.html
ErrorDocument 404 /http_errors/en/404.html
ErrorDocument 405 /http_errors/en/405.html
ErrorDocument 408 /http_errors/en/408.html
ErrorDocument 410 /http_errors/en/410.html
ErrorDocument 411 /http_errors/en/411.html
ErrorDocument 412 /http_errors/en/412.html
ErrorDocument 413 /http_errors/en/413.html
ErrorDocument 414 /http_errors/en/414.html
ErrorDocument 415 /http_errors/en/415.html

ErrorDocument 500 /http_errors/en/500.html
ErrorDocument 501 /http_errors/en/501.html
ErrorDocument 502 /http_errors/en/502.html
ErrorDocument 503 /http_errors/en/503.html
ErrorDocument 506 /http_errors/en/506.html

nginx (at nginx.conf or external included in ginx.conf)

error_page 400 /http_errors/en/400.html;
error_page 401 /http_errors/en/401.html;
error_page 402 /http_errors/en/402.html;
error_page 403 /http_errors/en/403.html;
error_page 404 /http_errors/en/404.html;
error_page 405 /http_errors/en/405.html;
error_page 408 /http_errors/en/408.html;
error_page 410 /http_errors/en/410.html;
error_page 411 /http_errors/en/411.html;
error_page 412 /http_errors/en/412.html;
error_page 413 /http_errors/en/413.html;
error_page 414 /http_errors/en/414.html;
error_page 415 /http_errors/en/415.html;

error_page 500 /http_errors/en/500.html;
error_page 501 /http_errors/en/501.html;
error_page 502 /http_errors/en/502.html;
error_page 503 /http_errors/en/503.html;
error_page 504 /http_errors/en/504.html;


«/http_errors» should be in «DocumentRoot» for this configuration.

Download link:
http errors v1.1.0 (12 KB)

Things TODO:
1) want to make tool, for auto generation of these files and to inject there you name and home page links (probably on Java).
2) need to add some open source license

See also:
Hypertext Transfer Protocol -- HTTP/1.1
Status Code Definitions

No comments:

Post a Comment