Welcome! Log In Create A New Profile

Advanced

Re: Why 301 permanent redirect with appended slash?

Francis Daly
July 31, 2019 08:06AM
On Tue, Jul 30, 2019 at 05:12:01PM -0500, J. Lewis Muir wrote:

Hi there,

> I have a minimal nginx.conf with one server block that sets the root
> directory and one location with a prefix string of "/foo/", and for a
> request of "/foo", it returns a 301 permanent redirect to "/foo/". Why?
> I expected it to return 404 or similar. I also tried a prefix string of
> "/foo", but that also results in the same 301.

I get a 301 if the directory "foo" exists; and a 404 if it does not.

Do you get something different?

> But in my case, I don't believe the request is being processed by any of
> those *_pass directives.

If you request "/directory", and "directory" exists, then the filesystem
handler will issue a 301 to "/directory/", which I think is what you
are seeing.

As in: your request for "/foo" does not match any location{}, and so is
handled at server-level, which runs the filesystem handler and returns
200 if the file "foo" exists, 301 if the directory "foo" exists, and
404 otherwise.

Change your config to be

location /foo/ { return 200 "location /foo/\n"; }

and you will see when that location is used.

If your config has

location /foo {}

then a similar consideration applies, except the request "/foo" is now
handled in that location which, per the above configuration, uses the
filesystem handler.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Why 301 permanent redirect with appended slash?

J. Lewis Muir July 30, 2019 06:12PM

Re: Why 301 permanent redirect with appended slash?

Francis Daly July 31, 2019 08:06AM

Re: Why 301 permanent redirect with appended slash?

J. Lewis Muir July 31, 2019 12:46PM

Re: Why 301 permanent redirect with appended slash?

Francis Daly August 01, 2019 12:56PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 300
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready