What could be causing too many redirects?

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.

Have you tried this? examples/Caddyfile at master · caddyserver/examples · GitHub

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.

This is weird. Nginx is now doing the same thing!

Even weirder. It’s a Safari-specific. Chrome and Firefox don’t do this. They work.

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.

I solved the file not found. Path was wrong. However, now I get can’t write into the config. Caddy runs as www-data but

drwxrwxr-x  2 www-data www-data  4096 Mar 18 02:13 config

fpm-php was running as the wrong user. Now it’s working in all browsers.

It’s not quite clear what was causing the redirects or the index.php as text in Safari. The only thing I changed was the Caddyfile configuration.

PHP is hard. :confused: Glad you got it working! :+1:

Thanks. I swapped my working configuration, which you linked to, with this minimal one

root /var/www/localhost/htdocs/nextcloud
log /var/log/caddy-access.log
errors /var/log/caddy-errors.log
fastcgi / php {
	env "HTTP_AUTHORIZATION" {>Authorization}

And I am getting the redirects. So this configuration IS causing the redirects, somehow.

This is required to prevent the redirects

rewrite {
               r ^/index.php/.*$
                to /index.php?{query}

What exactly does it do?

A request that looks like /index.php/foo will be treated as a request for /index.php, with any query parameters included.

1 Like

I still don’t quite understand. Why is there a “?” following index.php and what is meant by query parameters?

The ? is the beginning of the query string in a URL, query strings are key=value pairs, the keys are usually called parameters.

So what would /index.php/foo get changed to? It seems the /foo will be stripped off unless it’s magically turned into a query string.

A few examples for the rewrite r ^/index.php/.*$/index.php?{query}:

GET /index.php/example?foo=barGET /index.php?foo=bar

GET /index.php/some-dir/another-dir/etc?foo=bar&query=trueGET /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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.