Status code 404 not being returned

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
cguanaja
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Aug 14, 2021 12:54 am

Status code 404 not being returned

Post by cguanaja » Wed Sep 15, 2021 5:41 am

This was working and the only change I’ve done is making the site multilingual.
  • error.php file is under template’s location and has the correct code, /opt/bitnami/apps/joomla/htdocs/templates/lt_strategy_onepage
  • copied error.php file under above location to templates/system also
  • accessing any invalid resource does not return 404 status code but rather 301, 302 and 200 - I’ve used online tools and screaming frog SEO spider tool also
What needs to be done so invalid resources return status code 404? Please note that in the front end, browsers do show the 404 error page but just the status code on the back end which is not right.

Will appreciate a second pair of eyes - thanks!

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24974
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Status code 404 not being returned

Post by pe7er » Wed Sep 15, 2021 7:35 am

cguanaja wrote:
Wed Sep 15, 2021 5:41 am
What needs to be done so invalid resources return status code 404?
If you use the error.php when having a HTTP Status code 404 to display an article "Page not found" from your site,
then the "Page not found" will be successfully displayed and generate a HTTP status code of 200 "Success".

For my multilingual website (5 languages under 5 top level domains) I use the following error.php that load /error (a menu item with alias "error" that loads a "Page not found" article) and for each language it loads its own error menu item + page.

Code: Select all

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;

$errorPages = ['en-GB' => 'error', 'es-ES' => 'error-404',
'de-DE' => 'fehler', 'nl-NL' => 'fout', 'fr-FR' => 'erreur'];
$languageTag = Factory::getLanguage()->get('tag');

if ($this->error->getCode() == '404')
{
    header("HTTP/1.0 404 Not Found");
    echo file_get_contents(URI::root() . '/' 
    . $errorPages[$languageTag]);
    exit;
}
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

cguanaja
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Aug 14, 2021 12:54 am

Re: Status code 404 not being returned

Post by cguanaja » Thu Sep 16, 2021 1:08 am

Appreciate the input here @pe7er - quick questions for you.

- let's say for 'en-GB' => 'error', 'es-ES' => 'error-404' - are error and error-404 pages that you have with the respective output? Having each page associated with a menu and language?
- which one is the tag returned for get('tag')?

Thanks.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24974
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Status code 404 not being returned

Post by pe7er » Thu Sep 16, 2021 7:54 am

cguanaja wrote:
Thu Sep 16, 2021 1:08 am
Appreciate the input here @pe7er - quick questions for you.

- let's say for 'en-GB' => 'error', 'es-ES' => 'error-404' - are error and error-404 pages that you have with the respective output? Having each page associated with a menu and language?
Yes, that's correct.
"error" = the alias of a menu item of type Single Article and associated to English, which links to an English article "Sorry, not Found". Same goes for "error-404".
Same for Spanish but in Spanish "error" is also "error". As I used that alias in the English menu already, I decided to use "error-404".
- which one is the tag returned for get('tag')?
On English pages the get('tag') will be 'en-GB' and on Spanish pages 'es-ES'.
From my array of languages/aliasses, I get the correct alias to retrieve that menu item.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”