Custom Error Page allows you to have your own custom personal error pages instead of using the web hosting provider’s error pages or having no page. This makes a website look very much professional in the unlikely event of an error. Web master can also write scripts to notify him if there is an error.

How to setup Custom Error Pages: The .htaccess file and PHP

Example: I use a PHP script on to automatically e-mail me when a page is not found. These are some of the most common errors:

  • 400 - Bad request
  • 401 - Authorization Required
  • 403 - Forbidden
  • 404 - Not Found
  • 410 - Gone

The .htaccess file is what Apache web servers use to allow you to fine-tune your web server configurations at a directory level. Other types of web servers handle the customization of 4xx error pages differently.

How to Set Up A Custom Error Page

Step One

  • Creating/Modifying the .htaccess File: You can simply create one with a text editor (such as Notepad on Windows).
  • If you are using Notepad on Windows, you will need to enter ".htaccess" (including the opening and closing quotation marks) into the "Save As" dialog box when you create the file, otherwise Notepad will append a ".txt" extension when it creates the file.
  • Add the below line of code in .htaccess file. You will of course need to put error-4xx.html files in the main web directory for the above directive to work. The "ErrorDocument 4xx" directive essentially tells the Apache web server that it has hit a 4xx error and and use the document specified in the URL that follows.
//Custom 400 errors
ErrorDocument 400 <local-path>/error-400.html

//Custom 401 errors
ErrorDocument 401 <local-path>/error-401.html

//Custom 403 errors
ErrorDocument 403 <local-path>/error-403.html

//Custom 404 errors
ErrorDocument 404 <local-path>/error-404.html

//Custom 410 errors
ErrorDocument 410 <local-path>/error-410.html

Step Two

Creating Your Error Document File: http://www.example.com/error-4xx.html
It is not good enough to simply let your visitors know that the file could not be found. In order not to lose them, you will need to provide them some way to locate the document they want, or they will leave.

Your page should have one or more of the following things:

  • A link to your website homepage.
  • If you have a search form for your website, you should definitely put a search box on that page.
  • A link to your On-Page Sitemap, which lists all the pages on your website.
  • Has the robots meta tag: ‘noindex, follow’
  • Has a unique Title Tag
  • Has normal crawlable navigation on-page
  • Does NOT use any form of redirection

Step Three

Testing the Error Document - When you're satisfied with your page, upload it together with your .htaccess file to your website. Then test it by typing a URL that you know does not exist. Your error page should load up. From this error page, test to see that the links here lead to the pages you intended it to lead.

  • Do NOT Use Canonical Tag: Using a Canonical URL tag in Error will create a serious URL confusion for search engines. Example: A homepage link in canonical URL tag of 404 Error page.
  • Do not use relative URLs in the Custom Error Pages
    <a href="sitemap.html">Site Map</a>
    instead use absolute URL
    <a href="http://www.example.com/sitemap.html">Site Map</a>
  • Use Descriptive and Unique Title Tag.
  • Has Normal Crawlable Navigation (header, footer and left/right navigation)
  • Has the robots meta tag: ‘noindex, follow’ <meta name="robots" content="noindex, follow" />
  • Use relative URLs in your .htaccess file and not absolute URL or else it will cause Apache to issue a redirect to the browser rather than a hard 404 error. This is generally a bad thing, because Web robots (e.g. search engine spiders) won't be able to find broken links easily.
    ErrorDocument 4xx /error-4xx.html
    ErrorDocument 4xx http://www.example.com/error-4xx.html

           

Add a comment



About the Author
Joydeep Deb

experienced in Online Marketing, Web Technologies, Search Engine Optimization, SEO, SEM, SMM, Web Master, eMail Marketing, Web Analytics, MIS Reporting, Web Design and Development.

Lives in Bangalore, Karnataka - India and working as an Program Manager SEO at Cisco Systems Inc.

Get social with Joydeep at Twitter | Facebook | Google+ | LinkedIn

Subscribe to Newsletter

Receive my latest posts right in your inbox? Enter your email address below to subscribe.

Blog SEO 2015 - Strategies, Trends and Techniques How to Update Nokia Phone Firmware / Software Types of Facebook Users (Fun Post) Website Analysis: Gain Authority, Popularity How to setup Custom Error Pages SEO Overview: What? Why? And How? How to Verify Authorship (rel='author') in Google SERP Website URL Structure Strategy How to avoid duplicate content issue caused by mobile website URL Rewriting SEO Friendly: Convert Dynamic URLs into Static URLs What should we do with the website expired pages? Leverage your .htaccess file efficiently Google Image Search: Observation Mobile SEO Best Practices All about SEO Meta Tags Page Speed Best Practices Social Media Share Button Update: Twitter Apps and You Yahoo! and Bing Search Alliance HTML5 Overview - Introduction to HTML5 Best Practices for Custom Error Page Geo Location Targeting in Google SERPs Social Media Mistake List of HTTP Response Status Codes How to position DIV at the center of web Google Search: Rich Snippets for Events How to Suck at Social Networking Send PPC traffic to landing page and not homepage XML Sitemap Best Practices What is Canonical URL Tag? Utilize your 'robots.txt' file efficiently Keys for a successful Website Why paid search numbers often don't match How Accurate is your Web Analytics Data Optimize Your Landing Pages Guidelines while building a Corporate Website Guidelines for eMail Newsletters DO's and DON'Ts - Search Engine Optimization (SEO) Search Engine Optimization (SEO) Gyan - Fundas Tools MISC