2

I'm looking at changing the products URLs' structure on a Prestashop (v1.5) website. This process is quite straight-forward and it can be done instantly through the corresponding admin panel.

The thing is, many of the products are indexed on Google (and other search engines too I'm guessing) so I'd like to 301-redirect the old links until the indexers update themselves with the new URLs. I'm guessing it's probably the safest way to handle the change: avoiding 404s and duplicates.

Since I have hundreds of products in this shop, I'm not looking to redirect them one by one, obviously. But then I don't really know how to manage the structure change properly within an htaccess file.

At the moment, I'm using the default Prestashop structure:

{category:/}{id}-{rewrite}{-:ean13}.html

Which produces the following links:

http://www.sitename.com/category/123456-product-name-0123456789123.html

I'm now looking at changing it to the following structure (which I think might be more efficient because you can find the same words on category and product names):

{rewrite}-{id}-{:ean13}

Which would produce this kind of link:

http://www.sitename.com/product-name-123456-0123456789123

But now I don't really know how to handle the change, if it can even be done easily?

And without any changes, the old links aren't automatically redirected to the new ones.

1 Answer 1

1

Using a RedirectMatch directive from mod_alias in your .htaccess file should do the trick:

RedirectMatch permanent /[^/]+/([0-9]+)-(.*)-([0-9]+)\.html$ /$2-$1-$3

This pulls out the matching parts of your old URLs and redirects them to the new format.

3
  • Well, that was easy, feeling kinda dumb now... :) Thanks a lot, it works!
    – shroom
    Oct 29, 2014 at 16:15
  • Hi can you please confirm how to implement this in .htaccess where to add this line RedirectMatch permanent /[^/]+/([0-9]+)-(.*)-([0-9]+)\.html$ /$2-$1-$3
    – user53529
    Jun 24, 2015 at 10:25
  • It is best to add it at the top. That way it takes precedence over other rules. Jun 24, 2015 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.