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.