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;

1 Answer 1

0

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .