nginx return adds trailing slash to url

Alexander McNulty asked:

This redirect adds a trailing slash which breaks the link I would like to spend people to, the exact code follows:

server {
    listen 80;
    return 301$request_uri;

currently when someone enters into their browser, they are redirected to this url is not acknowledged. Survey monkey will only recognize

could someone help me remove the trailing slash. Thank you in advanced.

My answer:

You asked for the URL path to be appended to the redirected URL, by using $request_uri. Thus, if you go to you’re redirected to, because the requested URI is /. Further, if you go to then you are redirected to, because it’s /because.

If you just want people to be redirected to the same URL, regardless, then you should not have $request_uri here.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.