7

how do you make Joomla return a "real" 404 code? I can't figure out how to make this happen! I have changed htaccess.txt to .htaccess, enabled the system / redirect plugin, and turned on rewrite URLs in the the Joomla global options.

However, any fake URL I type in simply redirects to the homepage, not even to the default Joomla error page.

This also happens even on the Joomla demo site here: https://demo.joomla.org/badurl_fake

Testing further:

Joomla Global Use Rewrite: OFF
Joomla htaccess.txt renamed: NO
Joomla redirect plugin enabled: NO

This results in a bad URL returning a true 404 error

Joomla Global Use Rewrite: ON
Joomla htaccess.txt renamed: NO
Joomla redirect plugin enabled: NO

This results in a bad URL returning a true 404 error

Joomla Global Use Rewrite: ON
Joomla htaccess.txt renamed: NO
Joomla redirect plugin enabled: YES

This results in a bad URL returning a true 404 error

Joomla Global Use Rewrite: ON
Joomla htaccess.txt renamed: YES
Joomla redirect plugin enabled: YES

This results in a bad URL returning user to homepage

Joomla Global Use Rewrite: OFF
Joomla htaccess.txt renamed: YES
Joomla redirect plugin enabled: YES

This results in a bad URL returning user to homepage

Joomla Global Use Rewrite: OFF
Joomla htaccess.txt renamed: YES
Joomla redirect plugin enabled: NO

This results in a bad URL returning user to homepage

So it seems to me that the htaccess is the culprit here. In my testing, anytime the .htacess is present, the 404 is redirected to the index page.

  • Have you made any changes to your .htaccess file? Or is it the default file that ships with Joomla? – johanpw Sep 29 '14 at 19:02
  • No. Straight default running on Ubuntu lamp stack. – user101289 Sep 29 '14 at 19:04
  • @user101289 What component are you using for your homepage menu item? Com_content or something else? – David Fritsch Oct 2 '14 at 0:27
2

This isn't an error but expected behavior. If you navigate to Components > Redirect in the Joomla Administrator's interface, you will see a list of all URLs requests resulting in a 404. Joomla automatically records them in this component and the re-routes the request to the home page.

The reason why is two fold, first is to prevent a negative user experience by mitigating error pages and secondly, to provide a means for a website admin to track and manually re-route to desired endpoints. I attached a link to Joomla docs explaining in more detail.

http://docs.joomla.org/Help33:Components_Redirect_Manager

  • @Brian-- is there no way to override this and show "proper" 404? – user101289 Sep 29 '14 at 17:39
  • Yes, disable the system plugin redirect. – Brian Bolli Sep 29 '14 at 17:42
  • redirect plugin disabled, it still redirects to index with no 404 – user101289 Sep 29 '14 at 17:43
  • also, I am not seeing any entries in the redirect component, with or without the plugin enabled. – user101289 Sep 29 '14 at 17:58
  • What version of Joomla are you using? – Brian Bolli Sep 29 '14 at 18:02
2

You can customize the 404 error (example show a custom page or send somewhere other than the homepage) by adding a PHP file to your template, name it error.php and place it in the root of the template (next to the index.php of the template).

Inside that file you can indicate what to do, for example send to somewhere in your site (update /SOMEWHEREINYOURSITE with the desired URL):

<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

//example of a way to output the error code:
//echo $this->error->getCode();

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

Method 2:

Knowing that you are using the .htaccess file (which I assume you are using an Apache server), you can add a definition for what to do with the 404 error.

Place this at the top of the .htaccess file:

ErrorDocument 404 /SOMEWHEREINYOURSITE

As with the previous method, update /SOMEWHEREINYOURSITE with the desired URL.

  • 1
    The default /template/system/error.php can also be coppied to your template as a lot of them do not come with one. – tristanbailey Oct 2 '14 at 14:30
  • User should copy it becouse after an update file in system dir can be overwrited – bumerang Oct 26 '16 at 14:02
1

I have recently seen this on a few sites and just discovered that it happens when the site is in offline mode and you are logged in to the frontend.

When the site is online and you make up a url you get the standard error page with status code.

When the site is offline and you are logged in, you get redirected to /index.php with a 303 see other status code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.