Make the 404 page use the same template as the other pages - Forum | JoomShaper
Solved Helix Framework

Make the 404 page use the same template as the other pages

Asked by pulsar agency 1 year ago Last activity 1 year 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

Accepted answer

Marked as the solution
pulsar agency Asked this

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;

}

3 more replies

pulsar agency Asked this
1 year ago · edited

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

Ziaul Kabir Staff

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,

pulsar agency Asked this

Thanks, the issue is fixed

Ziaul Kabir Staff

You are welcome.

Log in to reply.