how to remove trailing slash on post request nginx

configuration, nginx, redirect, trailing-slash

Solution

The `permanent` will cause the `rewrite` to generate a redirect with a 301 response. What you need is an internal adjustment of the URI before sending it upstream:

location /x/y {
    rewrite ^/(.*)/$ /$1 break;
    ...
}

See this document for more.

Problem

I'm trying to remove trailing slash on http post method, when i try to re-write the URL using `rewrite ^/(.*)/$ /$1 permanent;` it doesn't work for me The upstream should receive in this format `/x/y` if the Http POST is coming in these format - location /x/y/ ==> location /x/y - location /x/y ==> location /x/y This is the nginx configuration ``` upstream backend { server 127.0.0.1:8778; # Number of idle keepalive connections per worker process. keepalive 35; } location /x/y { limit_except POST { deny all; } proxy_pass http://backend; proxy_buffering on; include proxy.conf; } ``` The problem here is when the upstream see the URI is in this format `/x/y/` it rejected the request, what should be the correct rewrite rule for this so that if the http post comes in the format like `/x/y` or `/x/y/` the upstream should always see `/x/y`

Original source