How to create a custom 404 error page joomla

A 404 error page is created from a broken link or a mis-typed URL. With a 404 page you can show your visitors know what went wrong.

Mostly all joomla templates have 404 error page. In case you are not happy with it, this article will show how to create a 404 error page for your joomla website. The advantage of creating the error page in this way, is that your website will keep the main menu and will display the error as article.

Step 1 - Create an article and select as category ‘uncategorized’. Write the text you what to show in the error page or even add an image.

404 error page

 

In this article click the "Publishing" tab and on the "Robots" field select "No index, no follow" to prevent this page to be indexed in search engines.

404 joomla page

Save the article.

Step 2 - Create a menu item. In Menu Item Type * select "Single article" and in Select Article * select the 404 page which was created on the first step.
On Options tab put everything in Hide and click save.
Copy the link which is created in the Link field of this menu item.

Joomla Menu link

Step 3 - Find your error.php file which should be located in /templates/YourTemplate/error.php. If your template don't have an error.php file, create one in main root of your template: templates/YourTemplate/error.php.

Make sure that you have security code at the top of the file:

 defined( '_JEXEC' ) or die( 'Restricted access');

To redirect the error to the custom 404 error page, in error.php add the code:

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

Replace the location information (URL404Page) with the URL from the menu item you created.

404 index joomla


Print   Email