One of the most common uses for a .htaccess file is to create custom error pages. The Apache server comes pre-installed with several different error pages, the problem with them is that they are quite frankly…. ugly. In order to use custom error pages we just need to add the following line(s) to our .htaccess file (for instructions on how to create a .htaccess file please refer to this post):

ErrorDocument errornumber /errorfile.extension

W e replace errornumber with the number corresponding with the Apache Error:

  • 400 -- Bad Request
    

  • 401 -- Authorization Required
    

  • 403 -- Forbidden
    

  • 404 -- Page Not Found
    

  • 500 -- Internal Server Error
    

errorfile.extension gets replaced with the name of the file you wish to use as your custom error page. You can place this file anywhere on your server, as long as you specify the directory it is in if it isn’t in the root directory.

Here are a few examples:

ErrorDocument 404 /404.php
ErrorDocument 401 /errorpages/401.shtml
ErrorDocument 500 /errorpages/500/500.html

Published by Michael Boguslavskiy

Michael Boguslavskiy is a full-stack developer & online presence consultant based out of New York City. He's been offering freelance marketing & development services for over a decade. He currently manages Rapid Purple - and online webmaster resources center; and Media Explode - a full service marketing agency.

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *