Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Custom Error Page Using PHP

Tuesday, Jan 24, 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=""></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.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH