Custom error page is not working

There are times when your custom error page will not function the way it should. You can fix this using your .htaccess file. If you do not have a .htaccess file, you can create it. Most of the time, the custom page is not properly setup and so will not work. The first step on checking a custom error page that is not working is to check the codes and correcting any errors. Because this will involve using the .htaccess file, let us begin with how to create the .htaccess file. Before we go on into how to fix your custom error pages, let us take a look at what are custom error pages and the most common http error as provided by Google.

You will also want to read:

CPanel Security
CPanel Login Tutorial
CPanel Account Information Tutorial
Backup mysql database tutorial
I have a full backup of account through cPanel. How do I restore it?

What are Custom Error Pages?

Custom error pages are pages shown to your website visitors which match your website theme when an error has occured within your website. The error can be caused by different things, the most common is the 500 – internal server error.

Most Common HTTP Errors According to Google

Now, you might wonder, which are the most common HTTP errors that people encounter when they surf the Web? The basic idea here is that some of the people who encounter errors when they visit websites will want to know more about that error, and will go to the nearest search engine to do so. In short, Google’s search statistics should in this case be able to give us a pretty good idea of which HTTP errors are most common.

In a study using Google Insights for Search (a great tool for estimating the “popularity” of search terms) these 5 error codes were top:

The top 5 errors, according to Google

Here they are, listed and explained in reverse order, the five most common HTTP errors.

5. HTTP error 401 (unauthorized)

This error happens when a website visitor tries to access a restricted web page but isn’t authorized to do so, usually because of a failed login attempt.

4. HTTP error 400 (bad request)

This is basically an error message from the web server telling you that the application you are using (e.g. your web browser) accessed it incorrectly or that the request was somehow corrupted on the way.

3. HTTP error 403 (forbidden)

This error is similar to the 401 error, but note the difference between unauthorized and forbidden. In this case no login opportunity was available. This can for example happen if you try to access a (forbidden) directory on a website.

2. HTTP error 404 (not found)

Most people are bound to recognize this one. A 404 error happens when you try to access a resource on a web server (usually a web page) that doesn’t exist. Some reasons for this happening can for example be a broken link, a mistyped URL, or that the webmaster has moved the requested page somewhere else (or deleted it). To counter the ill effect of broken links, some websites set up custom pages for them (and some of those are really cool).

1. HTTP error 500 (internal server error)

The description of this error pretty much says it all. It’s a general-purpose error message for when a web server encounters some form of internal error. For example, the web server could be overloaded and therefore unable to handle requests properly.

Judging by Google’s search statistics, this problem is more than twice as common as 404 errors:


Also read:
Cannot See My Website Online After Upload, Why?
Character encoding in cPanel file manager
How To Create, Edit, and Delete a File in CPanel Using File Manager
Default Home Directory Folders
Getting Familiar With the cPanel User Environment


A General Guide to Creating Custom Error Pages

Always check up your web hosting documentation how to implement custom error pages, if allowed. Now here is how you can create a custom error page:

Start by taking a copy of your website template and saving it with the appropriate name for the error you are creating it for.
Include in the body (content) area:
a precise description of what has happened, written in plain english, not a techical explaination.
a search box if you have website search enabled on the website.
a link to the website sitemap. (the traditional type, not to be confused with the xml sitemaps for Google or Yahoo)
a list of possibly related links.
a contact form (or link to) so the visitor can notify you of the error.

Make the links to the images and styles for the page absolute as you may not know in advance what the relationship between your error page location and the page requested will be.
Add the necessary server side instructions to implement your custom error pages. Check below on specific codes and how to use the. On an Apache server you would use the .htaccess file for example.

How to Setup a Custom Error Page Using .htaccess

Simply add these line of codes to your .htaccess file:

ErrorDocument 400 /error-code.php
ErrorDocument 401 /error-code.php
ErrorDocument 403 /error-code.php
ErrorDocument 404 /error-code.php
ErrorDocument 500 /error-code.php
ErrorDocument 502 /error-code.php
ErrorDocument 504 /error-code.php

Now, create an image file or a text file and name it 404.jpg. This image can be saved in your image folder as you will see in this example and following the code below.

Create a file and name it: error code.php

Now insert this code above into your error-code.php:

<div><a title="Return to the Your website Homepage" href="yourdomainname.com"><img style="display: block; margin-left: auto; margin-right: auto;" src="your-domain-name.com/images/404-page.jpg" alt="" class="pull-center" /></a></div>


You will observe that the image created for the 404 page is linked in the code above and saved in the image folder. Wherever you save your image, just ensure that you enter the right path. In the sample, we have centralized the page alignment.

Also read:

How Do I Create and Delete a Parked Domain
How do I create and remove an Addon Domain?
How to Backup My Website in cPanel
How to Create a MySQL Database, a User and Delete Database in Cpanel


You may also want to use specific file names for your error page

That is another way to fi this problem. You should create the corresponding files and add these lines to your .htaccess file:

For custom 404 error page:

ErrorDocument 404 /~cpanel_username/404.shtml

For custom 500 error page:

ErrorDocument 500 /~cpanel_username/500.shtml

You may also ant to read: Accessing FTP Log Files


You may also want to different file names for your error pages. For example:

For custom 404 error page:

ErrorDocument 404 /4004.shtml

For custom 500 error page:

ErrorDocument 500 /5000.shtml

The above directives will apply recursively to all subdirectories as well.


How to create a .htaccess file in cPanel

You will simply access the filemanager section of your cPanel. Make sure you check show hidden files. Click on the link to New File button at the top left corner of your top menu bar and name the new file to be .htaccess. Save your new file by clicking the Create New file button.
Now, you should have a .htaccess file on your filemanager folder.

Now, we can look at how to setup the custom error page.

Also read: How to access raw log files


How to Turn Your Error Page into a Marketing Tool

Doing these three things will help promote your website through its error pages:

1. Search Box - One great feature is to have a search box that is featured prominently on the page. Your visitor was clearly looking for something , and while they may not have found it on their last click, a quick search should send them in the right direction.

2. Navigation - You also probably want to include a site navigation section, so that visitors can continue browsing your site immediately, without having to go back a page.

3. Fun - Some websites like to include apologies in their 404 pages. These aren't totally essential from a usability stand point, but they can go a long way to calm a visitor who might otherwise be frustrated.

Final Words - Remember What You Can Include in Your Custom Error Page

A custom error page is, at the very least, a chance to have some fun with your website. Of course, it still needs to be useful. So when you’re creating one, here’s a quick run-down of what you should kkeep in mind:

A brief note explaining there’s been an error. Readers need to see straight away that they’re not where they think they are.
An explanation of why this has happened. The most common reasons are a typo or broken link, but try not to make it sound like you’re blaming the user. ‘Something went wrong’ is a far more neutral statement than ‘You’ve done something wrong.’
A navigation bar. There’s nothing more irritating than an error page that has no options for moving onwards, so keep your main navigational elements to allow people to try somewhere else. It’s important to make it as easy as possible for them to stay on the site – at this point, they’ll be frustrated and tempted to leave.
Links to other pages the user might need. It’s hard to know exactly where they thought they were going, but it’s nice to suggest some places anyway. Your homepage or most popular pages are good options to start with.
Contact information for any enquiries. If you’ve kept your standard page footer, this will probably be included already. Having this means the person can get in touch if they can’t find what they were looking for or can’t be bothered to search for it.



Did this help fix your error problem? Give a vote below to help us know how useful this guide had been.

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

I have a full backup of account through cPanel. How do I restore it?

It is recommended that you maintain healthy backup of your website and possibly download the...

How To Create, Edit, and Delete a File in cPanel Using File Manager

This tutorial will be useful for you to understand how to create a file, edit a file or delete...

How to Create and Manage a MySQL Database

Create MySQL Database and User via cPanel The MySQL Database Wizard is another useful tool...

How do I create and remove an Addon Domain?

An add-on domain is a separate domain name that you add to your web hosting subscription with...

How to Set Up and Delete a Cron Job

A cron job allows you to run a certain command at times set by the job. For example, you could...

Powered by WHMCompleteSolution