How do I Get The Custom 404 Error Page To Return A 404 Code Instead Of 301? - Question | JoomShaper
SP Page Builder 6 is Here! Learn More →

How do I Get The Custom 404 Error Page To Return A 404 Code Instead Of 301?

A

Allen

Helix Framework 5 days ago

Hi,

I followed the directions at https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder to make my custom error pages for 404 and 403 errors. It works beautifully. However, the code returned to the requesting browser (googlebot) is 301 (permanent redirect) instead of 404. This is confirmed at https://tools.websiteadvantage.com.au/404-Error-Handler-Checker. This is also confirmed by @Pavel in his comment below the guidance. I tried Pavel's correction advice from 5 years ago, but it does not work today.

Per the recommendation at https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder, the custom code recommended that we added to our PHP looks like this:

// custom 404 redirect
$config = JFactory::getConfig();
$sef = $config->get('sef');
$sef_rewrite = $config->get('sef_rewrite');
$sef_suffix = $config->get('sef_suffix');
$redirect_url = JURI::base();
if(!$sef_rewrite) {
    $redirect_url .= 'index.php/';
}
$redirect_url .= '404'; // menu alias
if($sef_suffix) {
    $redirect_url .= '.html';
}
// if sef is turned off
if(!$sef) {
    $redirect_url = 'index.php?option=com_sppagebuilder&view=page&id=107';
}
if (($this->error->getCode()) == '404') {
    header('Location: ' . $redirect_url, true, 301);
    exit;
}

When a bad URL is used The requestor receives a 301 fro the redirect, and then a 200 for the new page. For example:

Status Code,Scheme,Host,Path
301,,www.certifiedinfosec.com,/zdfhh
200,,www.certifiedinfosec.com,/404

When a web server encounters a resource that does not exist, and a custom 404 page is configured to be displayed, the custom 404 page should still return an HTTP status code of 404 (Not Found).

What do I need to add or change to make the page return a proper 404 code for links that are no longer valid?

Thanks.

0
7 Answers
Toufiq
Toufiq
Accepted Answer
Senior Staff 4 days ago #207605

Hi there,

Thank you for reaching out. To check the issue from our end, please create a staging site and share its login credentials with us. Make sure you provide only the staging site details, not the live site access. This is important because if any issue occurs while we’re working, it will affect only the staging site, not the live one. We want to maintain full transparency between the user and our support team.

Best regards,

Toufiqur Rahman (Team Lead, Support)

0
A
Allen
Accepted Answer
4 days ago #207613

The code I am using to redirect 404 error codes to a custom SPPB page is not custom. It is code provided by Joomshaper itself at https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder for over 5 years. Why do you need me to create a staging site on our server to test and fix the code Joomshaper created?

The code created and provided by Joomshaper does not correctly redirect, and then revert a 404 code back to the requestor as it should. It never has. This is not a unique or new issue. The problem was already independently noted by @Pavel over 5 years ago as you will see in the comments at the bottom of your own page providing the custom 404 page guidance. The comment is still there for you to read to this day, and is conveniently at the top of the comments ;-). Just click the link above!

Why are you asking me to create a staging site on our server? If you need a staging site to experiment and correct your own code you provide to all of your Joomshaper customers at your site, I recommend you create a staging site at your end.

Once you get it fixed, I further recommend you revise and correct the guidance Joomshaper has been providing at https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder for the past 5 years so you will not continue to propogate a recommendation that unnecessarily hurts SEO for your customers.

Aren't these reasonable and logical requests?

0
Toufiq
Toufiq
Accepted Answer
Senior Staff 3 days ago #207699

Please check this URL.

0
A
Allen
Accepted Answer
3 days ago #207749

Hi Toufiq,

I see that you have a staging site there. What do you want me to do with this regarding this formum post? What is the purpose of giving me access to a staging site? Please clarify.

Regards,

Allen

0
Toufiq
Toufiq
Accepted Answer
Senior Staff 3 days ago #207751

Reason to share website URL with login info, produce the issue on this site and we will check the issue.

0
A
Allen
Accepted Answer
3 days ago #207758

??? What???

I already provided all of the information to reproduce in the original post, and I don't need access to a staging server for any reason. I even provided screen captures and links for you to be able to validate that the code Joomshaper is recommending for creating a custom error page is indeed redirecting error codes to a custom page (I set mine to the home page to re-capture any SEO juice), but the redirection results in responding to the request with a redirect 301 code without responding with a proper 404 code for the original bad link.

Please re-read my original post carefully and respond with any questions you may have. Seriously. Please read the comments at the bottom of your own page at https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder as I already advised in the original post. Please. Pretty please. Pretty please with cherries on top!

0
A
Allen
Accepted Answer
2 days ago #207902

Bump.

0