"Joomla 404 Component Not Found" Page Change - HotThemes

Search Form and Social Buttons

HotThemes Logo and Top Menu

Joomla installed on your server will change default browser's 404 page to something what you can see on this picture. It's not perfect, but still better than default browser error page. At least, there's a link that leads to the home page of your web site. 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 web site 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 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 web site by referring them to the other pages. 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 Joomla administration panel create a content page where visitors will be redirected after 404 error. Some nice examples of such pages can be found here. 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 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 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?

In Joomla 1.6, 1,7 and 2.5, 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 upgrade, if needed.

Links, Partners and Social Media