how to rewrite-target context path within and without trailing slash?

2/4/2019

Im trying to solve context routing in kubernetes nginx ingress
when i enter context path /foo/bar in app controller received /bar it's correct
but when i enter /foobar in app controller received /bar but it not supposed to route.

I try /foo//?(.*) it's correct but if i enter /foo (without slash) it became an error 404

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: hello.info
    http:
      paths:
      -  backend:
           serviceName: hello-svc
           servicePort: 80
         path: /foo/?(.*)

so i expect that /foo or /foo/ should go to /
and /foo/bar go to /bar
and /foobar get an error 404
and /foo/bar/hello should go to /bar/hello

-- Jutinant Mahawongsanant
kubernetes-ingress
nginx-ingress

0 Answers