Want To Be A Blogger  →  Start A Blog  →  Increase Traffic  →  Make Money Online  →  Recommended Things

Custom Error Page Using PHP

Friday, Dec 15, 2017

Tags:- PHP Htaccess

When someone visit a page in your website and if the page is not found or the page is forbidden and or the webpage encountered internal server error than a default server webpage will be display which is not customisable and visually beautiful.So, in this tutorial we will show you how to create custom error page using PHP.

Custom Error Page Using PHP

To Create Custom Error Page It Takes Only Two Steps:-

  1. Create or modify .htaccess file and write redirect method
  2. Make a HTML file and define markup and styling

Step 1.Create or modify .htaccess file and write redirect method

#Rewrite URL's
RewriteEngine On
RewriteRule ^error/?$ errors/error.html [NC]

# Enable Error Documents
# (404,File Not Found) | (403,Forbidden) | (500,Internal Server Error)
ErrorDocument 404 /error
ErrorDocument 403 /error

In this step we create a .htaccess file in server main directory and write some rules for error page.We turn the rewrite engine on so we can redirect url to our custom error page then we define rules for 404 (File Not Found), 403 (Forbidden) and 500 (Internal Server Error) webpage to redirect when any of these error occur to 'error.html' page which we were going to create in next step.

Step 2.Make a HTML file and define markup and styling

We make a HTML file and save it with a name error.html

 margin:0 auto;
 font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;
 margin:0 auto;
#wrapper h1
#wrapper a
<div id="wrapper">

<h1>Soory For The Inconvenience Please Try Again Later</h1>
<a href="http://talkerscode.com">TalkersCode.com</a>


In this step we create a simple page which is displayed on any of these errors written above.

That's all, this is how to create custom error page using PHP.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Subscribe Our Newsletter And Get Tutorials And Offers Via Email

About Me

Hello, My Name is Mudit Jain. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of TalkersCode. I started this blog in february 2015 to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers.