1

I'm using nginx for the first time and I can't seem to figure this out. I'm trying to rewrite my nginx config so that all of my URLs no longer have the trailing slash that nginx defaults to.

I've been trying the following, but it still results in a redirect loop ("Firefox has detected that the server is redirecting the request for this address in a way that will never complete."):

    server_name_in_redirect off;
    rewrite ^/(.*)/$ /$1 permanent;

Any ideas on what might be going wrong here and how I can remove trailing slashes?

1 Answer 1

4

Actually... it's a firefox tendency to add a trailing slash to everything.

Your nginx config is removing it and firefox is adding it back to the request. Use 'curl -I' to check your config. Trying to enforce having or not having a trailing slash is going to cause you a lot of headaches.

If you absolutely need that, you need to remove the permanent and leave it an internal redirect.

From:

rewrite ^/(.*)/$ /$1 permanent;

To:

rewrite ^/(.*)/$ /$1;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The only helpful advice I've found on this issue is that browsers add the trailing slash back on and turn it into an infinite loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.