I see a similar topic posted here, but it’s closed without an answer:
tl;dr: I need to translate this rewrite rule from Nginx to a Caddyfile:
# Required for legacy support
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
I maintain a script to install Nextcloud in a TrueNAS CORE jail using Caddy as the webserver. It’s been working well for some time, but with the release of Nextcloud 28, multiple file uploads and downloads have been failing. Discussion on the Nextcloud forum has pointed to the absence of the above rewrite rule.
If I’m reading that rule correctly (in which I have very little confidence), it says to rewrite anything that does not begin with index or remote or public or… to /index.php{uri}.
So under that understanding, and in hopes of getting rid of the regex (both because I don’t know RE2, and to make the Caddyfile more readable), I inserted this block in the Caddyfile:
# Required for legacy
@legacy {
path /index*
path /remote*
path /public*
path /cron*
path /core/ajax/update*
path /status*
path /ocs/v1/updater/*
path /ocs/v2/updater/*
path /ocs-provider/*
path */richdocumentscode/proxy
}
rewrite !@legacy /index.php{uri}
But Caddy doesn’t want to start with this in there, giving the following error:
Error: adapting config using caddyfile: parsing caddyfile tokens for 'rewrite': wrong argument count or unexpected line ending after '/index.php{http.request.uri}', at /usr/local/www/Caddyfile:48
My guess is that I’m using incorrect syntax to invert the named matcher, but I haven’t been able to find what the correct syntax is–or if it’s even possible. Or should I just try to translate the regex to RE2?