2

I have an comparison website based on woocommerce and I have the following problem.

I have 1 product from 2 vendors:

Vendor 1: https://example.com/lista/ceas-accurist-signature-7220-classic/

Vendor 2: https://example.com/lista/ceas-accurist-signature-7220-classic-2/

Through .htaccess I want to 301 redirect all the links that finish in -2/ to the original one, without -2/.

Any idea how I can build the .htaccess rule based on that suffix -2/?

2

Try the following at the top of your .htaccess file:

RewriteRule (.*)-2/$ /$1/ [R=301,L]

Any URL that ends in -2/ is redirected to the same URL without -2.

The $1 (in the substitution string) is a backreference to the captured group (the part before the -2/) in the RewriteRule pattern.

| improve this answer | |
  • 1
    Thanks so much mate. It works. Highly appreciate your effort! – Gabriel B. Mar 16 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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