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 Answers1

0

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

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