Identified it as a bug when the file matcher is used on rewrite redirectives only – quite a niche bug you’ve found yourself, there!
The reason is because the root
directive is evaluated after rewrite
is, so the site root hasn’t been set when rewrite
's matcher is evaluated: Caddyfile Directives — Caddy Documentation
The easy fix is I can move root
up so it’s the first directive evaluated… but this means that if the request is rewritten, the root will not change, if it depends on the rewrite.
The thing is, it’s impossible to know which order the user intends, unless they use a route block.
But, I’m willing to bet that rewriting based on the existence of a file is more common than setting the root based on a rewritten URI. So, I can change the standard order.
In the meantime, using a global option of order root before rewrite
at the top of your Caddyfile ought to do the trick:
{
order root before rewrite
}