Avoiding 404 errors is very important, especially if they occur due to incorrect site-setup. It is a sign of bad website design, and could scare off both users and Google. Secondly, for the cases you cannot foresee,make sure that people never end up with a meaningless 404 Page not found error message. Especially the default Joomla page for this is very ugly. As it is completely different from the rest of your site, people may even think the site is broken and leave it. If this happens often it can negatively impact your SEO rankings. Best is to create a custom 404-page matching the design of your template. If your error-page makes sense to users, they will usually simply follow your directions, if you provide links to your search page or the homepage. 

Avoid 404 errors

By the way, first of all you should try to prevent people from actually encountering the 404-page at all. Especially try to avoid renaming articles and menu-items (unless you leave the alias in place!), as it will break URLs. Also make sure you do not have internal links leading to non-existing pages. These are the kinds of errors that are really bad for SEO. If you really have to rename URLs, make sure to use a 301-redirect to point the old URL to the new one.

Also make sure to monitor 404-errors using the Redirect Manager component (or use extensions similar to that). Also you can use non-Joomla services to crawl your site and detect 404-codes. You can do this using tools like Screaming Frog SEO spider or free services like www.brokenlinkcheck.com or the SEO audits that WebCEO and SemRush offer.

Be aware that not all 404-errors are bad. If you have an article or a webshop-product on your website that is no longer relevant, removing it will indeed lead to page-not-found error, but in this case it is valid use, and after some time Google and Bing will simply remove the page from the index. Google actually stated that this situation won't hurt your SEO.

Create a custom 404-page in Joomla

In many cases, your template provider might cater for a 404 page, but if it doesn't, or if you build your own templates, there is quite an easy way to create a custom 404 page in Joomla:

  • First, just create an article that will be displayed to the user when he receives the error.
  • Call the article whatever you want (404, error page, etc.) and just type a nice text, plus links to your Home or Search page.
  • Now write down the article-ID of the article (the last column if you are in the Article Manager overview). In our example, it is 999.
  • Optionally (but recommended): set the Robots-setting for the article to NOINDEX, NOFOLLOW to avoid having Google index it.
  • Optionally, add the article to a (hidden) menu
  • Then create an empty file called error.php in your current template's root folder

Then we have 2 options here:

Option 1: simply show a 404-page (less advised)

This is the standard solution that is also shown on other blogs, but it is not the preferred one (see option 2). This option will give you a simple 404-page, routing you to the 404-page after an error has occurred. Basically, simply create a new error.php file in your own template's folder, with only this code:

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

Replace 999 with your own article ID. 

If you assigned the 404-article to a menu-item, you can even make the code a bit cleaner. If you assigned it to a menu-item called Page not Found, the line starting with header... now becomes:

header('Location: page-not-found');

The disadvantage of this method is that it the browser still receives a 200-header response code, which makes it hard for search engines to determine that this page is actually no longer existing. This method results in so-called soft-404's. Read this blog on the Webmaster blog to understand why this behaviour is discouraged.

Option 2: Improved code with correct HTTP-response

An alternative which is much better than the example above is to slightly rewrite the code:

defined('_JEXEC') or die;
if (($this->error->getCode()) == '404') {
header("HTTP/1.0 404 Not Found");
echo file_get_contents(JURI::root().'index.php?option=com_content&view=article&id=8');

What this does is to send a 404 HTTP header to the browser, stay on the same URL, and retrieve the content of the 404 page, instead of just going there. This results in so-called hard-404's, which is the way to go.

Then a final note about these solutions: many commercial template providers have their own mechanisms of providing 404 pages, which sometimes makes it hard to use this solution. Anyhow, as long as they cater for a 404-page themselves, this is not a problem.

Run a Full Website Scan in Minutes

Joomlaseo.com is fully built and written by Simon Kloostra, Joomla SEO Specialist and Webdesigner from the Netherlands. I have also published the Joomla 3 SEO & Performance SEO book. Next to that I also sometimes blog for companies like OStraining, TemplateMonster, SEMrush and others. On the monthly Joomla Community Magazine I have also published a few articles.

Joomlaseo.com is not affiliated with or endorsed by The Joomla! Project™. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.
© 2021 Joomlaseo.com. All rights reserved.