How to create custom error page using .htaccess

Different types of error you want to cover

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

Now create a .htaccess file and put following code in your .htaccess file

RewriteEngine On
ErrorDocument 400 /badrequest.php
ErrorDocument 401 /authreqd.php
ErrorDocument 403 /forbidden.php
ErrorDocument 404 /pagenotfound.php
ErrorDocument 500 /internalerror.php

You can name error page whatever you want. In the above example all error pages located in the root folder.

.htaccess file must be in root folder.

Recommended Tutorials for you


Anuj kumar

This is Anuj Kumar. I’m a professional web developer with 5+ years of experience. I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials. .

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button