Help set up a WordPress bypass with a static cache

An index.html file inside a folder per URL generated by WordPress, like this :

➜  007-spectre-mendes la
total 36K
-rw-r--r-- 1 caddy caddy 33K May 11 01:06 index.html
➜  007-spectre-mendes pwd
/var/www/voiretmanger.fr/wp-content/cache/cache-enabler/voiretmanger.fr/007-spectre-mendes

I think the / is there because Caddy removes it from {uri} placeholder ? I’m not sure if it’s even necessary, but I know it’s working fine this way. :slight_smile:

The only rule that worked for me was the path_regexp one. I could not make the other three work.

I forgot to mention it in the recap, but as you can see in earlier posts, I added a header to see what route was used for each request.

Right now, using this setup, I always have the “file” value, so the named matcher takes every request.

    @cache {
        not {
            header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
            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)"
            method POST
            expression {query} != ''
        }
    }

    route @cache {
        header cache file
        try_files /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
    }
        
    header cache wp
    php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
}
1 Like