PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to disable prestashop's page-not-found redirect?

 June 30, 2022     http-status-code-404, php, prestashop, prestashop-1.6, redirect     No comments   

Issue

I have a Prestashop 1.6 installed on a VPS hosting and all is working well with it, except that when I try to reach a page that doesn't exist, instead of serving the 404 page of the template, a 301 redirect is returned and the client is redirected to index.php?controller=page-not-found where the 404 template is shown.

This is not working for me due to SEO reasons. How do I disable this redirect?

Thanks


Solution

Turns out the default behavior of prestashop is to redirect. It was not a override. Anyway - I found a way to achieve what I wanted to do anyway.

After some time struggling with that - I came up with a retarded solution, that will do for now. I am sharing it here, because I sure would have appreciated finding it few days ago, but be warned - it is retarded to the point of no return. Not recommended if you can come up with something else.

What I did was this - I found the CategoryController.php file in the controllers/front/ folder. There should be this row:

if (!$this->category->active)

In it I make a php file_get_contents request to the 404.html page of the website, and serve it. Afterwards I terminate the php script with an exit(); command.

This way the server sends out the 404.html content, without redirecting. Here is the full code:

header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');

echo file_get_contents('https://website.com/404/'
false,
stream_context_create(
array(
'http' => array(
'ignore_errors' => true
)
)
)
);
exit();

Don't forget that if the controller is overridden it might not work properly.



Answered By - GillighanJ
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing