Creating a Custom 404 Page in Joomla

If your template doesn’t come with a pre-configured error 404 page we highly recommend that you create one.  This is a pretty simple process.

  1. Go to article manager and create a new uncategorised article to act as your 404 page.  Commonly this will have a message saying "Sorry, the page you were looking for could not be found."   You might also want to include a search widget for the site or some navigation or a fun image.  This can all be coded in the article.
  2. Create a menu link to the article – I often create a menu called hidden and place it in that.  Take the link code from that article and copy it to notepad for later.
  3. Copy the error.php from the Templates/System directory to the directoryt of the template that is in use.
  4. Modify the error.php code to redirect 404 errors to the 404 article you created. 
    • look for this code:
    • if (!isset($this->error))
      $this->error = JError::raiseWarning(404, JText::_(‘JERROR_ALERTNOAUTHOR’));
      $this->debug = false;
    • replace with this code:
    • if (($this->error->getCode()) == ‘404’) {
      header(‘Location: index.php?option=com_content&view=article&id=43‘);
    • substitute the Location: link for the URL from the article that you created.

After you finish test that the site is working properly and test to ensure a failure url redirects properly.

You can then go into the robots.txt file located in the root directory and add the following line:

Disallow: /index.php?option=com_content&view=article&id=43

Replacing the /index.php?…. with the 404 article url.

© 2020 All Rights Reserved.