Make The 404 Page Use The Same Template As The Other Pages - Question | JoomShaper

Make The 404 Page Use The Same Template As The Other Pages

pulsar agency

pulsar agency

Helix Framework 9 months ago

Hi .

on https://www.pulsar-agency.com/ we use the Helix Ultimate KONSTRA template. Our question is about the 404 page which is handled with the templates/konstra/error.php file.

how can we make the 404 page use the same templates are the other pages of the site ? Then it will have the same header and footer

Thanks

0
5 Answers
pulsar agency
pulsar agency
Accepted Answer
9 months ago #182807

ok found: file_get_contents() requires allow_url_fopen to be set to ON which is a security breach a safer way is to : write in the error.php file :

function getPageContentSecure($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Suivre les redirections curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Timeout pour éviter les blocages curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Vérifie le certificat SSL

$output = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  // Récupérer le code HTTP
curl_close($ch);

if ($http_code == 200) {
    return $output;
} else {
    return '<h1>Erreur lors du chargement de la page 404</h1>';
}

}

if (($this->error->getCode()) == '404') {

header("HTTP/1.0 404 Not Found");

$url = JURI::root() . '404';
echo getPageContentSecure($url);

exit;

}

1
pulsar agency
pulsar agency
Accepted Answer
9 months ago #182802

I was wrong about not being able to insert the page with the site header and footer.

Following https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder I did it on https://www.pulsar-agency.com/404 but if you try to enter a wrong url you will be redirected to this custom 404 page as a 301 which is bad for SEO. The 404 page should come with the 404 error code

If you replace header('Location: ' . $redirect_url, true, 301); with : header("HTTP/1.0 404 Not Found"); echo file_get_contents(JURI::root().'404');

it gives you nothing

0
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 9 months ago #182814

Hi,

Thanks for reaching out to us.

It looks like you’ve found a working solution using cURL. Do you still need any help optimizing it or ensuring the 404 page fully integrates with your template? Let me know if you need further assistance!

Best regards,

0
pulsar agency
pulsar agency
Accepted Answer
9 months ago #182832

Thanks, the issue is fixed

0
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 9 months ago #182835

You are welcome.

0