stop automatic trailing slash addition

Francis Daly francis at daoine.org
Sat Dec 13 08:00:41 UTC 2014


On Fri, Dec 12, 2014 at 04:00:29PM -0800, neubyr wrote:

Hi there,

> I was wondering if it's possible to have separate namespaces for '/test'
> and /test/'.

They are different requests, and different request prefixes, so yes,
they can be handled in different location{}s.

>       location /test {
>           root         /usr/share/nginx/test;
>         }
> 
>          location /test/ {
>            root         /usr/share/nginx/test-slash;
>            try_files $uri default.txt;
>         }
> 
> I tried above configuration, but nginx adds trailing slash to all '/test'
> requests before they get processed by location directives. So all requests
> are going to '/test/' location.

Have you evidence of this unexpected behaviour?

A trailing slash should not be added by nginx before location{}-matching.

> Is there any way to get separate namespace for /test and /test/ ? This not
> for real world website. I am trying to learn more about location directive.

What you have should do it. But I am not clear on what precisely you
wish to happen.

What request do you make? (Presumably something like "curl -i
http://localhost/test" or "curl -i http://localhost/testA")

What response do you get? (A http redirect? Or perhaps the content of
a particular file on your filesystem?)

What response do you want? (The content of a different file on your
filesystem? Name the files, so it is clear where the expectation and
the result are different)

For what it's worth, enabling the debug log can show lots about what
the location-matching engine is actually doing during a request.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list