Caddy is ignoring the redirect and status configuration. The page was transitioned from nginx to caddy and some redirects needed to be carried over from the old configuration.
As you can see in 4. Caddy is not redirecting but sending the site to the fast_cgi processor and php returns a 404 code because the page does not exist. Instead it should just return a 301 with the other page.
Same thing happens for the /autodiscover/ url. This one is sent to php too instead of just being rejected by caddy with a 404.
This means that due to this fairly widely scoped rewrite:
The paths you’ve set manual status or redirect on:
Get rewritten away from these paths before those directives ever operate, unless they’re paths with a corresponding file/indexed directory in the webroot (because you rewrite to {path} {path}/ first). By the time it gets to redirect or status, the path has likely become /index.php?.
The solution should be to ensure the rewrite doesn’t do that. This should work:
rewrite {
if {path} not_starts_with /wp-admin
if {path} not_starts_with /autodiscover/
if {path} not_starts_with /new-customer
to {path} {path}/ /index.php?{query}
}
(Note that I have also rewritten your first if statement to use a substring check instead of a regex, which saves a few CPU cycles).
I think I found the link you gave about the order of middleware chaining by myself but concentrated more on fastcgi than rewrite rules. The rewrite rule is also copied from the caddy Wordpress repository so it never occurred to me that this rule could do any harm.
Perhaps the caddy documentation should mention the order how middleware is chained so this could be easier to spot/debug.
Possibly, yeah - it’s kinda hinted at in the HTTP Caddyfile doc, but never stated outright as far as I know. It’s something that is handled differently in Caddy v2, though; directives are executed in order of appearance in the configuration, so your above example (adapted for v2) would have worked perfectly.
Is that the case overall, or just in the Caddyfile? Obviously my recollection on this is poor but I remember talking about this in relation to JSON config.