You can’t use a full chain of logic on a single if subdirective. The syntax is if a cond b, each instance must take three arguments.
Instead, specify multiple if subdirectives.
if specifies a rewrite condition. Multiple ifs are AND-ed together. a and b are any string and may use request placeholders. cond is the condition, with possible values explained below.
if_op specifies how the ifs are evaluated; the default is and .
The rest is the same - use multiple if subdirectives. With if_op or set, the rewrite can be executed if any of the conditionals match, instead of all of the conditionals having to match.
I’m afraid not. and is not a subdirective of rewrite. The rest looks good.
The only subdirectives you can use are regexp, ext, if, if_op, and to. Give the docs another read, specifically the syntax section: https://caddyserver.com/docs/rewrite
You don’t specify between each if statement whether they’re grouped AND or OR. You simply specify all the conditions, then you can optionally specify how all of them are grouped.