You’re right, I tried both these solutions and none worked, exactly for the reason you explained.
Using the solution given by @francislavoie, it seems to work though.
I will wait and see for a couple of days, but if I can confirm it works fine, I will open a Wiki for this special edge case. It’s really a proof of the strength of Caddy 2, compared to Caddy 1 or even the other webservers out there.
Gladly, let me know if there is something useless here. I have already removed the php_fastcgi from the cache route, I guessed it was not necessary and indeed, it works fine without.
(static) {
@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.json
}
header @static Cache-Control max-age=5184000
}
(security) {
header {
# enable HSTS
Strict-Transport-Security max-age=31536000;
# disable clients from sniffing the media type
X-Content-Type-Options nosniff
# keep referrer data off of HTTP connections
Referrer-Policy no-referrer-when-downgrade
}
}
voiretmanger.fr {
root * /var/www/voiretmanger.fr
encode zstd gzip
file_server
import static
import security
log {
output file /var/log/caddy/voiretmanger.fr.access.log
}
# Redirect personnels
redir /a-propos/publicite /soutien
redir /archives/carte-des-restaurants /a-manger
@cache {
not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
not method POST
not expression {query} != ''
}
route @cache {
try_files /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
}
php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
}
Is there something else I should reorganise/get rid of/change ?
I think your alternative is just the inverse of the inverse. To match that logic expression (a bunch of OR’d NOTs), any path that’s missing any of them would pass (i.e. only the presence of all of them would constitute a failure to match), whereas AND’d NOTs would fail out if any single one of them were present, which is the desired result and matches the functionality of the actual matcher you specified immediately after.