Browse By

Easily Create Custom Error Pages

Chances are we’ve all been to a web page that no longer exists and have been staring at an error page that looks plain and provides virtually no useful information (other than the warning saying the page no longer exists). That’s because Apache has included hard coded error pages in its httpd server, and while they get the job done, the job could be done better in just a few small steps. Custom error pages can be developed to help provide more information about the error, to automatically redirect the viewer to a landing page, and to integrate your site design.

Apache’s ErrorDocument Directive can be used to display the default page packaged with the server or show custom error pages tailored specifically for your site. The 5 most common custom error pages used are listed below.

  • 400 – Bad Request
  • 401 – Authorization required
  • 403 – Forbidden
  • 404 – Wrong page
  • 500 – Internal server error

Creating custom error pages can be accomplished simply by creating a web page for each (or one web page accepting dynamic input) and adding a few lines to your htaccess file. I have listed examples for a static page for each error and a dynamic page for all errors below. This code should be added to your htaccess file.

Static Pages

ErrorDocument 400 /error/custom_400.html
ErrorDocument 401 /error/custom_401.html
ErrorDocument 403 /error/custom_403.html
ErrorDocument 404 /error/custom_404.html
ErrorDocument 500 /error/custom_500.html

Dynamic Page

ErrorDocument 400 /error/custom_error.php?error=400
ErrorDocument 401 /error/custom_error.php?error=401
ErrorDocument 403 /error/custom_error.php?error=403
ErrorDocument 404 /error/custom_error.php?error=404
ErrorDocument 500 /error/custom_error.php?error=500

Each of these pages could be stored wherever you like. I used the “error” directory as an example, and you can name the files however you like, using whatever type of file you wish. The ErrorDocument directive allows you to redirect to an external URL as well as a local path.



One thought on “Easily Create Custom Error Pages”

  1. Pingback: » Easily Create Custom Error Pages Apache: What The World Is Saying About Apache
  2. Trackback: » Easily Create Custom Error Pages Apache: What The World Is Saying About Apache

Comments are closed.

%d bloggers like this: