Multiple handle blocks are mutually exclusive, meaning they allow a flow where only 1 of them is matched and executed. So, you can have something like this:
handle /file* {
forward_auth *.*.*.*:9091 {
uri /api/authz/basic-auth
}
}
handle {
forward_auth *.*.*.*:9091 {
uri /api/authz/forward-auth?authelia_url=https://exmaple.com/auth
}
}
I actually read that, but I guess not carefully enough, and that’s on me.
Reading through it again, it seems that it my example, I should actually compare forward_auth and route, in which case forward_auth takes precedence. I think I can override it with order forward_auth after route, but then the part where forward_auth is not explicitly nominated would not have forward_auth.
So the example you provided is not only clearer but also the only way to go about it.
Using handle like I showed is certainly the most simple approach I think. You could get away with writing negated matchers for everything (cause there’s no else in Caddy, you’d have to basically duplicate the matchers but with not in front of them). That would be necessary to prevent your top-level forward_auth applying on requests further down in the config which might want to do a different forward_auth, etc.
But anyway, using handle blocks lets you write your config in a rough “if-elseif-elseif-else” kind of pattern (the last handle without a matcher being the else/fallback), and nested “if” within those as needed, etc.