What is a 404 error page?

joomlaSometimes visitors will try to access a page that doesn't exist.  On these occasions the visitor will get a 404 error page.  This article describes the process for helping the visitor with a page that tells them what to do next.


Create a custom 404 article

We will start by creating the article that we want to appear instead of the default 404 error page.

  1. Log into the backend of Joomla.
  2. Go to Content > Articles.
  3. Create an Uncategorised article and include some text such as 'Sorry, we could not find the page you were looking for...'
  4. Give it a meaningful Title (e.g. Ooops! You seem to be lost?).
  5. Add any useful navigational links. (e.g. a link back to your site's home page).
  6. Select the Publishing tab.
  7. For Robots, select No index, no follow.
  8. Save the article.


Create a link to the article

  1. Create a Menu called 'Hidden'
  2. Create a new menu item type Single Article.
  3. Select the article that you created in the previous step.
  4. Give your Menu item a meaningful Menu title (e.g. Error 404).
  5. Save the Menu item.
  6. Then copy the Link information (index.php?optio...).
  7. Set the menu item as Unpublished.
  8. Save and Close out of the menu editing page.

You may want to paste the copied URL into Notepad or somewhere accessible for the time-being.


Copy error.php to your Template's Directory

  1. Use your preferred File management (e.g. File manager on your web host).
  2. Browse to /templates/system.
  3. Copy the error.php file.
  4. Paste into the root directory of your template (e.g. /templates/protostar).

 

Edit the error.php file

Edit the newly created error.php to redirect 404 Errors to your newly created 404 Article

  1. Add the following code immediately at the top of the file (after the opening notes).
if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}

Replacing the location information (index.php?option..) with the URL that you copied in the previous step.

Note that this file will likely get overwritten if you upgrade Joomla, and you are using Protostar.

 

Thanks for visiting.