Create a custom 404 page in Joomla 2.5

There are a number of forum discussions at joomla.org on this topic, but none of them that I've seen cover the entire process in a simple manner. Here's what I do for a quick and easy custom 404. It's more or less what's here, but in simpler terms.

  1. Create a file named error.php and place it in your template's main directory (/templates/your_template/error.php). It should contain the following code:

    <?php

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

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

    ?>

    Be sure and change the URL to reflect your site's domain.

  2. Create an article containing your message with the title 'Oops!' (or 'D'oh!' or '404' or whatever you like). Place it in a category where it won't automatically show up on the site. I often use the following message, (though I did get more casual on this site):

    We're sorry, the page you were looking for could not be found.

    It appears that the page does not currently exist, or may have been moved. Please verify your address or visit one of the pages in the menu above.

  3. Create a hidden menu (simply one that isn't published via a module), and an item in it called 'Oops!' with an alias of 'oops'. (If your alias is different, you'll need to change the URL in the code above to reflect that.) Give it the type Single Article and point it to your new Oops! article.

That's it. Easy peasy. Now, if you break old article links or if someone mistypes an address they'll see a professional page rather than a cryptic Joomla or server error.