I’ve changed the SEO Schema settings in the PrestaShop back office (e.g. added .html extension for Product URLs).
Now, the old URLs don’t work anymore and they are not redirect to the new URLs (the ones with .html extension).
I’d like that whenever I change the settings for Products or Categories URLs, the previous URLs are redirected to the new ones (301 permanent redirects).
Any solutions?
2
Answers
For PrestaShop is not important if the URL end with/without .html, the real problem is if you has remove the ID in the route or changed the order of the ID, if this is your case you will need to create a large list of redirections (for each of the categories) in your .htaccess like this example:
Redirect 301 /3-my-old-category-url /my-new-category-url
By default, PrestaShop does not generate redirect rules based on your changes to handle old URLs (that would be complex to manage, especially in case you make multiples changes in a row).
You will have to launch a one-time script to generate these permanent redirect rules (301).
Here’s a example
The code below assumes that your old URLs were in this format:
/category/product
, adapt it if needed.Place this script in your PrestaShop root folder and launch it. Then, copy and paste the result into your .htaccess file.
You can also check this related question:
PrestaShop – RedirectMatch old product urls (without ID) to new url
I hope this helps!