0

Requirement- I want to redirect all requests that end with /abcd to /products/abcd

This should match all urls such as these-

  • /collection/abcd
  • /collections/all/abcd
  • /hello/world/abcd

This is what i'm using- rewrite /abcd/?$ https://example.com/products/abcd permanent;

The problem- if someone visits /products/abcd, this url also matches the rewrite rule, and goes into an infinite loop.

I also tried this regex, but that doesn't match any url (i.e. no redirects happen)- rewrite /(^products/)abcd/?$ https://example.com/products/abcd permanent;

0

I found a solution for this, which uses nginx location blocks-

location /products {}
location / {
    rewrite /abcd/?$ https://example.com/products/abcd permanent;
}

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.