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
3
Answers
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:
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:
Don't forget that if the controller is overridden it might not work properly.
I’ve done this in overrided Tools controller
public static function redirectLink($url)
{
}
A global solution for this (so you don’t have to go controller by controller) is going straight to the -> classes/Dispatcher.php
In there you will find the dispatch function.
You can do something like ->
before the line where the controller is going to be executed