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 which I want kong to redirect or add slash at the end as 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

  - |
    local forwarded_host = ngx.var.http_x_forwarded_host  or
    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+)

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

© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ