.htaccess – Creating error pages

When creating a website, you may need to create custom error pages. For instance, when a user enters wrong url, www.gad2.com/category/phone, instead he enters “www.gad2.com/category/pone”, server takes you to a default 404 error page, which indicates file not found error. In such cases we need to define custom pages, so that server loads the custom pages according to the error.


The code to be used in order to use custom error pages is

ErrorDocument 404 /error_pages/404.html

We can also include pages are other errors like 500,403 etc..

We can do that by changing error codes and html file.

ErrorDocument 401 /error_pages/401.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html

After adding separate custom error pages, server automatically redirects us. For example facebook redirects us to the following page on wrong url.


To know more about error codes, you can visit http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

I will continue writing more on .htaccess in my future posts. Thanks for reading.

Follow me


Web Developer at Energy Alternatives India
I'm interested in developing Web applications andkeen on learning new technologies.

View Nagarajan's Profile
Follow me

Latest posts by Nagarajan (see all)

Leave a Reply

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