I am trying to upgrade my Caddyfile from v1 to v2, and I have completed most content unless some url rewrite rules for Nextcloud, cause they are too difficult for me to convert so far. The related codes in the current Caddyfile v1 are listed below:
# PHP
fastcgi / 127.0.0.1:9000 php {
env PATH /bin
env front_controller_active true
env modHeadersAvailable true
}
# Functional rewrite
rewrite {
r ^/\.well-known/host-meta$
to /public.php?service=host-meta&{query}
}
rewrite {
r ^/\.well-known/host-meta\.json$
to /public.php?service=host-meta-json&{query}
}
rewrite {
r ^/\.well-known/webfinger$
to /public.php?service=webfinger&{query}
}
# Check for IMAGES and CSS JS
rewrite {
if {method} is GET
ext .js .svg .gif .png .html .ttf .woff .ico .jpg .jpeg .css
r ^/(.+)$
to /{1} /index.php?{1}
}
# For direct PHP using case
rewrite {
if_op or
if {path} starts_with /updater
if {path} starts_with /ocm-provider
if {path} starts_with /ocs-provider
r /.*
to {path}/
}
# Route the views to index.php
rewrite {
ext /
if_op and
if {path} not_starts_with /index.php
if {path} not_starts_with /remote.php
if {path} not_starts_with /public.php
if {path} not_starts_with /corn.php
if {path} not_starts_with /core/ajax/update.php
if {path} not_starts_with /status.php
if {path} not_starts_with /updater
if {path} not_starts_with /ocs
if {path} not_starts_with /.well-known/
r /(.*)
to /index.php?{query}
}
# Remove trailing as it causes errors with php-fpm
rewrite {
r ^/remote.php/(webdav|caldav|carddav|dav)(\/?)(\/?)$
to /remote.php/{1}
}
rewrite {
r ^/remote.php/(webdav|caldav|carddav|dav)/(.+?)(\/?)(\/?)$
to /remote.php/{1}/{2}
}
rewrite {
r ^/public.php/(dav|webdav|caldav|carddav)(\/?)(\/?)$
to /public.php/{1}
}
rewrite {
r ^/public.php/(dav|webdav|caldav|carddav)/(.+)(\/?)(\/?)$
to /public.php/{1}/{2}
}
It is hoped that someone can help me modify it to the right format for Caddyfile v2, any advice would be highly appreciated. Thanks!