How to Make a Quick & Easy 404 Error Page for Joomla 3+

The error page is processed through the file error.php which if not already in your template folder, can be copied over from templates/system/error.php and further edited. However, I like to keep things simple by having it just load a specific article from my install of Joomla. Here’s how.

404 Error

Btw! Find the lengthy custom error page documentation on Joomla.org here.

And, this will work with Joomla 3.8. 3.9, 3.10 and beyond.

404 Within Content

For this all I need is to create the file error.php in my template root with the following content:

<?php
defined('_JEXEC') or die;

if (($this->error->getCode()) == '404') {
header('Location: /404');
exit;
}
?>

and create an article with the a simple message like:

Error 404: Page Not Found
Unfortunately the page that you are trying to open does not exist.

As well as menu item pointing to the article, with the alias “404”.

404 on Individual Page

If for some reason I want the error page to be placed completely in it’s own page. An error.php like below should suffice:

<?php

if (!isset($this->error))
{
$this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
$this->debug = false;
}

// Get language and direction
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $this->error->getCode(); ?> - <?php echo htmlspecialchars($this->error->getMessage()); ?></title>
</head>

<body>
<!--- custom error page html here -->
</body>
</html>

Btw: I noticed that having Joomla in “Site Offline” mode will redirect 404s to index.php.  So to view the error page just open mydomain.com/404 and test the forwarding function itself once your site is online.

Easy peach!

Leave a Comment