Skip to content

Administrator Tips icon

Creating a Custom 404 Error Page with cPanel

Creating a custom 404 error page with cPanel takes only a few minutes. In this tutorial I will show you the quick way to get a custom 404 page onto your site by using cPanel's inbuilt functions, and will also show you how to create a static custom 404 for Mambo that looks like the rest of your site.

cPanel Error Pages

Login to your server's cPanel administration area. Locate the Error Pages icon and click.

custom error pages

A screen similar to this will load: cpanel error pages

Select the 404 (Wrong Page) option. This will open a basic plain text editor into which you type your content.

At the top of the editor textfield box cPanel gives you some suggestions for code that you can include on the page. You can include information such as:
Referring URL - <!–#echo var="HTTP_REFERER" –>
Visitor's IP address - <!–#echo var="REMOTE_ADDR" –>
Requested URL - <!–#echo var="REQUEST_URI" –>
Server Name - <!–#echo var="HTTP_HOST" –>
Visitor's Browser - <!–#echo var="HTTP_USER_AGENT" –>
Redirect Status Code - <!–#echo var="REDIRECT_STATUS" –>

If you want to have a simple, quick and easy custom 404 page all you need to do is enter one or more of these variables, and perhaps some basic HTML such as a header or a paragraph with suggestions for what the visitor should do next. You can also add links back to your home page or a search box if you wish.

Save, and enter an invalid URL for your site to see your new custom 404 error page.

Most people don't want such a basic, unstyled page on their Mambo or Joomla! web sites. In my earlier tutorial I explained how to create a custom 404 error page for Mambo using Mambo itself. On a very busy site, especially one that receives a lot of 404 errors, you may wish to keep server load low so creating a Mambo page for your 404 may not be what you want.

Creating a Static 404 Page That Looks Like Your Site

Creating a static 404 error page that looks like your Mambo site and uses the same headers, footer, and images is not difficult, even for the HTML and CSS challenged.

The first thing we do is we load up our site in our browser. Choose the shortest and simpliest page on your site. Then, in the browser source view, select all and copy/paste this into either a plain text editor or into your favourite HTML editing tool.

Open the file you have just created and locate the mainbody content. This is the content we are going to replace. For our static page, we will remove everything that is generated by Mambo's <?php mosMainBody(); ?> and remove all code associated with modules within our page (there is no point leaving code for search boxes or other content that cannot work outside of Mambo itself).

If you are using the default Mambo template, look for the code that start with this: <!– start main body –> <div id="content_main"> and remove everything between these lines and this: </div> <!– end main body –>. We want to keep the opening and closing div so that our 404 page content is styled the same way as our Mambo template.

Now, add your own 404 page content between <div id="content_main"> (or whatever your own mosMainBody content container may be) and </div>. You can use the variables I mentioned above, and you can add as much HTML code as you wish. Read the earlier tutorial for tips on what to include in your custom 404 page content.

NOTE: 404 error pages can be called from anywhere within your web site, so all links to URL's and images must be absolute links.

When you have added your content, view the page in your browser to test that everything works. If it works from your local computer it will work on your site.

Now we go back to cPanel. Login and go to your File Manager. Look for the file called 404.shtml.

404shtml
Click to select.

On the top right of the screen you will see the following options. Select Edit File. select edit file

When the basic editor opens, delete everything in the file then copy/paste everything from the static page you created. Save, then test by going to your site and entering an invalid URL.

This method can be used with any dynamic CMS and I have been successfully using it on Mambo and Joomla! web sites for years. There is no additional server load when using this method. The only downside is that when you change your template you do need to update the 404.shtml file if you want it to continue to look the same as your site.

Examples of 404 Pages for Mambo

For web sites using Microsoft's IIS, read this tutorial about using a custom error page with IIS.

Bookmark This:
  • bodytext
  • Technorati
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Reddit

Whether I am developing Mambo or working on tutorials I am fuelled by coffee. Caffeine keeps me going so if you like the work I am doing please click on the cup to buy me a coffee today. Just $10 covers the cost of getting my caramel macchiato ;)

If you enjoyed this article make sure you subscribe to my RSS feed!

Leave a Reply

This is a gravatar-friendly site, enter your email address to use your gravatar.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.