Rewrite-target query

Hello,

can you please help me to understand how rewrite-target works, with example. I understood the concept behind it but how it actuallly works, I am still confused.

e.g. If may URL is myapp.com/a/b/c

what will be the outcome for
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/rewrite-target: /$2

Thanks
Ashish

In ingress, any characters captured by (.*) will be assigned to the placeholder $2, which is then used as a parameter in the rewrite-target annotation.

For example, the ingress definition above will result in the following rewrites:

  • rewrite.bar.com/something rewrites to rewrite.bar.com/
  • rewrite.bar.com/something/ rewrites to rewrite.bar.com/
  • rewrite.bar.com/something/new rewrites to rewrite.bar.com/new

It is well explained in this documentation

Now it’s clear. Thanks.