Website Scripts And Cloud Tutorials

How to redirect custom Error Pages Using .htaccess

Byadmin

May 21, 2011 , ,

Last updated on January 17th, 2022 at 04:55 pm

Click to rate this tutorial!
[Total: 3 Average: 2.7]

A Simple Method To Create Custom Error Pages

.htaccess file is very helpful especially since it allow us to extend Apache configurations without the need to restart the webserver itself. These custom error pages will allow you to have your own, personal error designs (for example when a file is not found) instead of using your host’s error pages or default webserver page. Having custom error pages will make your site look much more professional in the unlikely event of an error. It also help us create scripts to notify webmaster if there are any errors.(For example redirecting errors to a PHP / Python script that enables notification in the background)
You can use custom error pages for any error as long as you are aware of the common error codes (like 404 for page not found) by adding the following to your .htaccess file:

ErrorDocument errornumber <FILE NAME>

For example if I had the file notfound.htm in the root direct
ory of my site and I wanted to use it for a 404 error I would use:

ErrorDocument 404 /notfound.htm

If the file is not in the root directory of your site, you just need to put the path to it:

ErrorDocument 500 /errorpages/500.htm

These are some of the most common errors:

401 – Authorization Required
400 – Bad request
403 – Forbidden
500 – Internal Server Error
404 – File Not Found

Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.

Click to rate this tutorial!
[Total: 3 Average: 2.7]

Leave a Reply

Your email address will not be published.