How to create a custom 404 page in Joomla?

Create custom 404 page in Joomla

Creating a 404 page in Joomla is essential as it tells the users that the page they are visiting isn’t found or broken. In this tutorial, I will explain to you the steps to create a 404 page. If the page isn’t found instead of 404 server error, a 200 HTTP code will be sent to the browser. This will also tell the search engine that page isn’t allowed to be crawled. So, now let us create it.

Step 1: Create an Uncategorized Joomla article

The first step is to create an article in the Uncategorized category. Set the title of the article to “404 – Page Not Found” and the alias to “404”. Add images or text which says “Sorry, the page isn’t found” or anything that you wish.

Step 2: Set the Robots to No Index, No Follow

The robots tell the search engine to either allow or disallow the page to index. As we don’t want the 404 to be indexed by the search engine. We have to set the Robots to No Follow, No Index in the Publishing tab of the Joomla article and Save the article.

Step 3: Create a Menu item

Once you have saved the article, create a Hidden Menu. To create it you can now go to Menus> Manage > Add Menu and fill the menu type and description.
After creating the Hidden Menu, navigate to Menus > Hidden Menu > Add New Menu Item

  • Add the Menu Title and Alias
  • Select the Menu Item Type as Single Article
  • Save the article and copy the Link (index.php?option=com_content&view=article&id=292)

Step 4: Create the error.php file

The error.php file is usually located in templates/YOUR_ACTIVE_TEMPLATE/error.php. If it doesn’t create an error.php file and add the following codes into it. Replace your link with your link into the header function below.

defined( '_JEXEC' ) or die( 'Restricted access');
if ($this->error->getCode() == '404')
{
header('Location: /index.php?option=com_content&view=article&id=292');
exit;
}

Save the file after adding the codes into error.php file of your template.

Step 5: Test your page

Once you have added the codes, test your website. Try to open a page which doesn’t exist. For example, www.yoursite.com/hahaha. If the site opens the 404 pages you have created, then everything works fine. If it doesn’t recheck the steps or contact us. We will help you out 🙂

Share the Article

Picture of Abhilash Sahoo

Abhilash Sahoo

Abhilash Sahoo, with 14 years of experience, is a Certified Joomla and WordPress Expert and the Founder & CEO of Infyways Solutions, specializing in innovative web development solutions.