Mmmm, I do not think this is necessarily true. I’m convinced the redirect is originating in your backend; Caddy only serves up a redirect from HTTP->HTTPS, when fixing paths for accessing static files (trailing slash whether it’s a directory or not) or when told to explicitly.
This causes some of php files to be interpreted as text. I have a test.php and that is interpreted properly, but index.php and status.php, both part of nextcloud render as text.
That applies to nginx. I went back to caddy and test.php works in Safari whereas I get file not found in Chrome and Firefox. Further under caddy, index.php also returns file not found in Firefox and Chrome, but appears blank in Safari.
A few examples for the rewrite r ^/index.php/.*$ → /index.php?{query}:
GET /index.php/example?foo=bar → GET /index.php?foo=bar
GET /index.php/some-dir/another-dir/etc?foo=bar&query=true → GET /index.php?foo=bar&query=true
GET /index.php/some-dir/ → GET /index.php?
So on and so forth. It just strips out everything between index.php and the query string, presumably so that the web server doesn’t treat index.php as a directory and 404 when it can’t find any files to serve. If there’s no query, it just has a ? on the end, which is a non-issue.