• Decrease font size
  • Reset font size to default
  • Increase font size

Who's Online

We have 14 guests online

PayPal Donation

Handling 404 Redirection in Joomla

Have you noticed those 404 errors or a strange url on your awstats getting a bunch of hits. This is due to invalid url's and/or non-existent files. Your host deals with invalid url's as a 404 error. In some cases joomla will catch the 404 error and provide a weak display message mostly confusing the viewer causing them to leave your site. In other cases your hosting service will capture your viewer with their message that usually contains advertising and links to other sites which will definitely have your customer leave your site. So if your finding you are getting a pile of 404 errors it is highly advisable to redirect your traffic back to your site. This can be done with just a few steps.

To make 404 error redirection more complete you will need to turn on Joomla's SEO. I have step by step instructions on how to do this, please read Basic SEO for Joomla.

Awstats on 404 statistics. If you don't deal with your 404 errors look at the next three examples to see how joomla, hostgator, and ixwebhosting deal with it. You will notice it is not too pretty and you will probably have to agree you would not want your site viewers to see these pages.

This is what Joomla will display in the viewers browser for a 404 error.

Another example showing how a hosting service will deal with a 404 error.

And yet another host 404 error catch page

Here is a quick tutorial on how to fix this problem. There are two ways you can go. The first would and simplest would be to redirect all 404 errors back to your home page. The Second would be to redirect the 404 error to a specific article on your website.

1) Copy the file templates/system/error.php to your default template location templates/<template-name>/error.php using either your hosts file manager or with a FTP client such as FileZilla.

2) Open error.php for edit

Change this original code near the top of the file

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>

To this (add the stuff in red). Don't forget to change <your-url> to your web site name!

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (($this->error->code) == '404') {
echo file_get_contents('http://www.<your-url>.com');
} else {

?>

Finally at the very bottom of the file add the following

<?php } ?>

3) Your done. Now you will not loose your site viewers to the dreaded 404 error pages. At this point they will be redirected to your home page. If you would like to have them go to a specific article telling the user that the requested page does not exist then continue with the following steps.

4) Create an article in Joomla Note down the Article ID

404 Page not found. The page your looking for does not exist.

5) Modify the error.php to contain the stuff in red. then change <article_id> to the Article ID you would like to show. Also don't forget to modify <your-url> to your sites url.

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (($this->error->code) == '404') {
echo file_get_contents('http://www.<your-url>.com/index.php?option=com_content&view=article&id=<article_id>');
} else {
?>

 
Copyright © 2000 to 2009 Linkapps.com All rights reserved.