caddy
caddy copied to clipboard
file_server canonization redirects should keep original query
Caddy's file_server directive, when not turned off by disable_canonical_uris, issues 308 redirects to canonical URLs if a request for a directory does not end with a trailing slash, or if a request for a plain file mistakenly ends with one.
This is very similar to any other web server. Unlike Apache HTTPD or nginx, however, Caddy snips and loses the query part (if any) of the original URL in the process.
For example, https://example.com/name-of-a-directory?query gets redirected to just https://example.com/name-of-a-directory/, with the query part deleted.
I was able to work around this in my Caddyfile config like this (only the redirects on directories gets the "fix" as I did not need the other direction):
map {query} {query_with_mark} {
"" ""
default "?{query}"
}
route {
@no_trailing_slash {
not path */
file {path}/
}
redir @no_trailing_slash {scheme}://{hostport}{http.request.orig_uri.path}/{query_with_mark} permanent
file_server browse
}
But I believe this should simply be the default behavior instead, requiring no further configuration, thus matching any other web server. Tested with Caddy v2.7.0-beta.1.
I think this is the same as #5254.
Unfortunately this is sensitive code and I haven't had a chance to properly review it yet. I don't think it'll make it in 2.7 but maybe 2.7.1.
I think this is resolved in #6109