I am trying to convert these to Caddy rewrite rules with no success, I have tried using the regex rules for rewrite on the last rewrite block, but that didn’t work, I also then tried the extension rules which also did not work. Any help would be greatly appreciated.
The main problem is with 2. Caddy’s rewrite can’t conditionally check whether a file exists before operating.
The closest approximation to this functionality is to rewrite to multiple targets, which will have Caddy pick the first one in the list that exists on disk.
There might be some workaround, but I can’t think of one right now. My advice, generally speaking in regards to WordPress (given how unbelievably common it is for WP developers to rely on quirks of Apache, since it’s deployed 99.99% of the time in shared cPanel hosting) is to just have Caddy proxy to Apache.
Can the second code example be converted though? It doesn’t seem to check for files existing, the first code block is not required for the plugin to work.
This line effectively says, “if the requested path is an existing file”. It’s pretty rare I see the -f flag, far more common I see the opposite, !-f (which is “if the requested path is not an existing file”), and also commonly paired with !-d (“the requested path is not an existing directory”), both of which Caddy can handle using the fallback method.