Re: curl 301 moved permanently if I don't use slash at the end of the url
On Tue, Mar 28, 2017 at 12:56:13PM -0400, c4rl wrote:
> I need to list the content of some directories with curl without to use a
> '/' at the end of the url.
There's a relative-url reason why that is usually not a good idea,
which is probably why the defaults for many web servers' "auto-index"
feature do not do it, and instead issue the http 301.
It is reasonable and possible to do the directory listing the way you
want, but it is likely to include some extra coding (rather than just
configuration) on your part.
> If I do not use the slash then I receive the message below, otherwise the
> content is showed. I tried many rewrite rules without success.
> [user@localhost ~]$ curl http://mydomain.example.com/data/foo
The important part of that response is in the http headers, that you
can see by (for example) adding "-i" after "curl". It will show the 301
response code, and the Location: header that includes the trailing /.
where you must write the code behind "my_special_autoindex" yourself.
Or, more likely, use something like "try_files" (possibly in a chain)
to handle a generic url; if it does not end in / and does correspond
to a directory, then invoke your extra code -- which might be handled
by a fastcgi script you write, or by something you write in one of the
embedded languages in nginx.
It is possible that someone has already wanted the same thing as you,
and written a module to do it.