Nope, it’s still there! https://caddyserver.com/docs/rewrite – look at the third and fourth examples. Use the to subdirective to specify which files to “try”.
Have a look in the Syntax section for the block version, specifically the parts for if and destinations:
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.
destinations… is one or more space-separated paths to rewrite to, with support for request placeholders as well as numbered regular expression captures such as {1}, {2}, etc. Rewrite will check each destination in order and rewrite to the first destination that exists. Each one is checked as a file or, if ends with /, as a directory. The last destination will act as default if no other destination exists.
With an understanding of what multiple to destinations means, the third and fourth examples should be exactly what you’re looking for. Just remove or modify the if and change /mobile/index.php to whatever suits.
If user agent includes “mobile” and path is not a valid file/directory, rewrite to the mobile index page.
rewrite {
if {>User-agent} has mobile
to {path} {path}/ /mobile/index.php
}
Thanks for replying. I have a better understanding now. So I am trying to understand the config from an earlier thread I linked to:
localhost:4000
root ./public
rewrite {
if {path} is /
to /proxy/{uri}
}
rewrite {
to {path} /proxy/{uri}
}
proxy /proxy localhost:8080 {
without /proxy
}
In this case why two rewrite statements are required? Only second rewrite block should be enough right?
Consider, if only the second rewrite were used, a scenario where a client requests /; the rewrite will evaluate {path}, based on the web root, and if it determines it is a real directory on disk (very likely), it will rewrite to this and not proceed to the second target (the proxy).
So the first rewrite forces all requests for / to be proxied, and the second rewrite checks for an existing file before rewriting.