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.

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

3 Answers 3

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

7
  • @Brian-- is there no way to override this and show "proper" 404?
    – user101289
    Commented Sep 29, 2014 at 17:39
  • Yes, disable the system plugin redirect. Commented Sep 29, 2014 at 17:42
  • redirect plugin disabled, it still redirects to index with no 404
    – user101289
    Commented Sep 29, 2014 at 17:43
  • also, I am not seeing any entries in the redirect component, with or without the plugin enabled.
    – user101289
    Commented Sep 29, 2014 at 17:58
  • 1
    I don't thionk this is intended behaviour. The redirect component is disabled by default. And redirecting error pages prevents you from detecting and fixing them. Error pages are there for a reason. I've been seeing this on a few sites recently and it seems to be a bug. Commented Apr 5, 2016 at 11:24
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.

2
  • 1
    The default /template/system/error.php can also be coppied to your template as a lot of them do not come with one. Commented Oct 2, 2014 at 14:30
  • User should copy it becouse after an update file in system dir can be overwrited
    – bumerang
    Commented Oct 26, 2016 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 and acknowledge you have read our privacy policy.

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