Joomla installed on your server will change the default browser's 404 page to something that you can see in this picture. It's not perfect, but still better than the default browser error page. At least, there's a link that leads to the home page of your website. Not bad, but could be much better.

The 404 error page without Joomla

The 404 error page with Joomla

Why is 404 page important? Why we are talking about it at all?

 

  • Out of date bookmarks in visitors' browsers
  • Search engines didn't update their listings for your website yet
  • Visitor mistype address when entering it directly in browser
  • Web sites that link to your site have wrong or out-of-date links
  • Many other reasons, but the above 4 are enough for you to get many 404 error response codes

What the 404 page should do?

  • Make visitors feel comfortable, even if they are on the 404 error page
  • Keep visitors on your website by referring them to the other pages. A good idea might be a search feature on the 404 page, so they can find what they are looking for fast and easy, without leaving your website and looking for the resource somewhere else

Create a custom "Joomla 404 component not found" page

First, in the Joomla administration panel create a content page where visitors will be redirected after a 404 error. Use Google to find even more examples. Assign a menu item to the page, and place it in a hidden menu (a menu which module is not published). Now, you have a link for this page that looks as a regular Joomla article link. It can be with SEO enabled or without it.

Change default "Joomla 404 component not found" page

The "system" template is included in the Joomla 1.5 installation. The file error.php located in <JOOMLA_ROOT>/templates/system handles display of error pages. In the beginning of this file, you should make a redirection to the custom 404 page you created. So, open it in the editor and after line

{codecitation}defined( '_JEXEC' ) or die( 'Restricted access' );{/codecitation}

add code:

if (($this->error->code) == '404') {
echo file_get_contents('http://www.yourwebsite.com/your_custom_404_page');
}
else
{

Redirection will be made only if the type of error is 404, so you should finish if-then statement by adding

<?php
}
?>

at the end of this file.

How about Joomla 1.6 and later?

In Joomla 1.6, 1.7, 2.5 and 3.x, the code should look like this:

if ($this->error->getCode()==404) {
echo file_get_contents('http://www.yourwebsite.com/your_custom_404_page');
exit();
}

Since we are editing a template that comes with Joomla, it's possible that it will be changed in some of the next revisions of Joomla core. Remember to re-apply this hack after an upgrade, if needed.