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.
^(.*)$
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.