How to setup custom error pages using .htaccess?

In this post, we going to see how to setup custom error pages using .htaccess. If you like to create a custom error pages is really useful, for the visitor it allows to show the user-friendly error message, in case if the URL does not work the error URL help to display the particular error page. Using this kind of method will help to avoids the unfriendly ‘404 File Not Found‘ error and it allows you to show a user-friendly error page, describing the better solution you can able to stay the visitor back into your website, rather than leaving them frustrated.

The following instructions will help you with how to use the error page.


ErrorDocument 404 /error/404.html

The above link which helps to display an error page and it tells to Apache Web Server the error page placed at error/404.html.

Here you can see how the error page will display. For example, http://www.softaox.info/error/404.html

Finally, you want to do this for each error to display a particular error page ( example: ‘400 Bad Request‘, ‘401 Unauthorised‘, ‘403 Forbidden‘, ‘404 File Not Found‘, and ‘500 Internal Server‘ error messages ). Now create a .htaccess file and add the following popular error lines.


ErrorDocument 400 /error/bad-request.html
ErrorDocument 401 /error/unauthorised.html
ErrorDocument 403 /error/forbidden.html
ErrorDocument 404 /error/file-not-found.html
ErrorDocument 500 /error/internal-server-error.html

Was this article helpful?

Yes No
×

How can we improve it?

×

We appreciate your helpul feedback!

Your answer will be used to improve our content. The more feedback you give us, the better our pages can be.

Follow us on social media:

Facebook Pinterest
Share via:

Mraj

Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts.

Leave a Reply