I'm trying to use Nginx to 301 redirect from http://something.example.com to http://another.site.com. The problem is that Nginx keeps adding a trailing slash which http://another.site.com doesn't know how to handle (this site is outside of my control).

Nginx Server Block

server {
    server_name something.example.com;
    return 301 http://another.site.com;

Is there are way to disable the trailing slash?

  • That slash is supposed to be there. It is the path component of the URL, which for HTTP/HTTPS must always begin with a slash. It can't be empty. If a URL doesn't have a path component, the slash will be added. Something that purports to speak HTTP that doesn't accept a path component with a single slash is so utterly broken that it should never have left the developer's workstation. So something else is likely going on. Read this. – Michael Hampton Feb 1 at 18:22
  • Honest question, why can I get away with typing https://google.com into the browser without a 301 redirect to https://google.com/ but I can't use Nginx to redirect without a forward slash? – Jack Slingerland Feb 1 at 18:24
  • 2
    The browser is adding the slash for you before it makes the request. Then it is being disingenuous and not showing the slash. – Michael Hampton Feb 1 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.