kubernetes-ingress icon indicating copy to clipboard operation
kubernetes-ingress copied to clipboard

Does path rewriting support regex?

Open pistoolster opened this issue 3 years ago • 3 comments

My yaml file likes

spec:
  rules:
    - host: my-host
      http:
        paths:
          - path: /api/path1/
            backend:
              serviceName: dev-svc
              servicePort: 80
          - path: /api/path2/
            backend:
              serviceName: dev-svc
              servicePort: 80

Is there a way I can rewrite

  • /api/path1/ to /api/v1/path1/
  • /api/path2 to /api/v1/path2/?

I tried

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: dev-ingress
  namespace: dev
  annotations:
    nginx.org/rewrites: serviceName=dev-svc rewrite=/api/v1/$1

doesn't work.

Thanks.

Aha! Link: https://nginx.aha.io/features/IC-414

pistoolster avatar Jan 24 '22 11:01 pistoolster

Hi @pistoolster thanks for reporting!

Be sure to check out the docs while you wait for a human to take a look at this :slightly_smiling_face:

Cheers!

github-actions[bot] avatar Jan 24 '22 11:01 github-actions[bot]

I checked https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/ and https://github.com/nginxinc/kubernetes-ingress/tree/v2.1.0/examples/rewrites

can't get any idea

pistoolster avatar Jan 24 '22 11:01 pistoolster

Hi @pistoolster

Unfortunately, we don't support regex in rewrites in Ingress resources. However, we do support them in VirtualServer resource -- https://github.com/nginxinc/kubernetes-ingress/tree/v2.1.0/examples/custom-resources/rewrites

pleshakov avatar Jan 25 '22 18:01 pleshakov