Add trailing slash at end of URI

Hi All,

I am trying to setup ingress kubernetes to add auto trailing slash end of the URI. I have abc.com/1/2 which I want kong to redirect or add slash at the end as abc.com/1/2/ and stop. I tried to have redirect setting using pre-fucntion plugin and but it adds infinite / and get to “too many redirection” error. How can I add / only when there is no slash in the URI?

I have tried below pre-function

  functions:
  - |
    local forwarded_host = ngx.var.http_x_forwarded_host  or ngx.var.host
    ngx.header["Location"] = "https://" .. forwarded_host .. ngx.var.request_uri .. "/"
    return kong.response.exit(302)

But it end up having too many redirect issue. Could someone please suggest how to solve this ?

Thank you.

Perhaps a request transformer plugin

i.e: Ingress defined path with RegEX
path: /(?\w+)

config: 
  replace:
    uri: "$(uri_captures['version'])/"

© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ