4

In this documentation

http://docs.joomla.org/Creating_a_Custom_404_Error_Page

there is advice to redirect to a custom 404 page by redirecting. This leads to the final page being served on a Header 200 code.

However this webmaster tools article

https://support.google.com/webmasters/answer/2409443?ctx=MCE&ctx=S4

requires the 404 error page to return a 404 header.

I have tried to include Joomla again from the error page. Short of using curl to get the custom page, is there anything else I can do?

2

This is called a soft 404 as you are redirecting to a different URL. So the 200 response after the redirect is correct, which, yes, does cause problems for search engine bots in determining if content is not found:

I was going to suggest, forcing a 404 response code to header call in error.php file like this:

if (($this->error->getCode()) == '404') {
    header('Location: /index.php?option=com_content&view=article&id=75', true, 404);
    exit;
}

However, this won't work — mainly because browser behaviour is either to go no further or undefined as far as I can tell (see 4xx errors, 404) which conflicts with location. (Also some Chrome & IE's et al ignore the content provided by the server when they see a 404 code and present their own "suggestions").

So, it would appear that to get custom content from an article and retain a 404 you need to get that content and include it in your error page (I'm presuming you want to do this so that you get your template, menu structure etc).

2

Here is what I ended up placing at the top of my error.php

<?php
/**
 * @package     Joomla.Site
 * @subpackage  Template.system
 *   * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights     reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
 defined('_JEXEC') or die;
if (($this->error->getCode()) == '404') {
    header('HTTP/1.0 404 Not Found');
    $ch = curl_init( JURI::root() . '/404');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    echo curl_exec($ch);
exit;
}
  • This worked for me. The setting of the header and the exit are important. You could also do a file_get_contents instead of a curl. – Klaasvaak Oct 16 '14 at 9:40
  • @klaasvaak and jdog.. please try this tool: test404page.com and tell me if this returns to you a 404 header. In my case, it returns nothing although i have set a similar error.php Thanks.. – Yannis Dran Aug 21 '15 at 8:01
  • @yannis dran I know it works for me because of what I see in Chrome inspector. Whats your website? Can you put up a separate question for your problem? – jdog Sep 16 '15 at 22:47
  • it is not only one website, but a few of them. I can't find the request in inspector. Can you please tell me how you found it? I checked several other websites and the same problem occurs that's why I asked. I don't think it worths a seperate question. – Yannis Dran Sep 17 '15 at 9:22
0

Pretty easy fix for Joomla custom soft 404 URLs that don't return the 404 header:

https://www.joomlashack.com/blog/joomla/custom-404/

Visible on: https://www.its-acoustique.fr/john-doe

  • 1
    Please always write the core/bulk of your answer as text in your answer. Link-only answers are low value on StackExchange sites because when the links die, the post becomes useless. Please take a moment to edit/improve this answer so that it is timeless and educational without leaving this site. Linking to external resources helps to fortify answers, so definitely don't delete them. – mickmackusa Oct 19 '18 at 10:24

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.