We recently moved from Magento 1 to 2, during the move we cleaned up our category urls to be more consistent. For instance we changed:


to :


SEO wise this is really destroying us and was wondering what the NGINX rewrite would be to

a) redirect the old category url to the new one and

b) make old product links work as before so that:


will redirect to:


By using the rewrite rule below

rewrite ^/mens/mens-(.*)/mens-(.*)$ /mens/$1/$2 permanent;

The nginx server should redirect (301) both of your category page and product page

Please note that this is only redirecting one category (mens) and products.

If you need redirection on other categories and products, then you would have to write additional rules to accommodate them.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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