I’m trying to reproduce the problem but am so far unable to. Can you provide more details? What is your exact request (give me a specific curl command for instance) and what is the expected result, and what is the actual result (paste its complete output).
No.1 I’d like it to go through and have the static file served
No.2 I’d like to rewrite to /app1/ so that /app1/index.html gets picked up and served, and the path (/app1/some-scope/some-page) is kept unchanged for the single page app to process
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: