0

I have a lot of products which currently have url structure like this:

https://www.mywebsite.com/product-name1

or

https://www.mywebsite.com/Product-name1 / capital P

I have rebuilded my website using WooCommerce and the default url structure looks like this:

https://www.mywebsite.com/product/product-name1

What would be the best approach to handle and append /product/ in each of the product urls and use the 301 redirect on them?

I have tried this:

RewriteEngine On
RewriteBase /

# Redirect old OpenCart URLs to new WordPress URLs
RewriteRule ^(.*)$ /product/$1 [R=301,L,NC]

And I believe somewhat it worked but it messed up some urls and products started loading without images and also /product/ was appended in my url when I browse the website and the admin section.

3
  • "and also /product/ was appended in my url when I browse the website and the admin section" - of course, because you are applying this to every request URL path - the pattern ^(.*)$ matches any path possible. If you don't have any way of differentiating product URLs from "other" URLs via some sort of pattern - then your only option is to implement explicit exceptions for the URLs you don't want to redirect.
    – CBroe
    Commented Apr 26 at 13:48
  • "and products started loading without images" - probably due to the fact, that those image requests also get redirected. But at least these images are probably located in some sub-folder (that you could also generally exclude from the redirects), I would assume?
    – CBroe
    Commented Apr 26 at 13:50
  • Yes you are correct , unfortunately I believe the only option will be exceptions or just to add 301 on all my products one by one.
    – Alexander
    Commented Apr 26 at 14:03

0