# BEGIN RunCache
# RunCache Plugin: Apache rewrite rules for serving cached pages.
# Bugs or questions? Email support@runcloud.io.
RewriteEngine On
# Mark requests that must continue to WordPress/PHP instead of serving a
# static cache file. This avoids fragile skip counts when cache rules change.
RewriteCond %{REQUEST_METHOD} !=GET
RewriteRule ^ - [E=RUNCACHE_BYPASS:1]
# Bypass cache for WordPress admin and system URLs.
RewriteCond %{REQUEST_URI} "^/(\.well-known|wp-admin|wp-login\.php|wp-cron\.php|wp-signup\.php|wp-activate\.php|wp-comments-post\.php)" [OR]
RewriteCond %{REQUEST_URI} "^/(wp-json|xmlrpc\.php|index\.php/feed|feed/?|wp-json/)" [OR]
RewriteCond %{REQUEST_URI} "(^|/).*sitemap.*\.xml$" [OR]
RewriteCond %{REQUEST_URI} "^/(cart|checkout|my-account)"
RewriteRule ^ - [E=RUNCACHE_BYPASS:1]
# Configurable query and cookie rules are evaluated by PHP after a miss.
RewriteCond %{HTTP_COOKIE} "(wp-postpass|wordpress_logged_in|wordpress_sec_|comment_author|wp-settings-)"
RewriteRule ^ - [E=RUNCACHE_BYPASS:1]
# Serve cached home page only when no bypass condition matched.
RewriteCond %{ENV:RUNCACHE_BYPASS} !=1
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/runcache/%{HTTP_HOST}/index.html -f
RewriteRule ^$ /wp-content/cache/runcache/%{HTTP_HOST}/index.html [L]
# Serve cached subpages only when no bypass condition matched.
RewriteCond %{ENV:RUNCACHE_BYPASS} !=1
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.+?)/?$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/runcache/%{HTTP_HOST}/%1/index.html -f
RewriteRule ^(.+?)/?$ /wp-content/cache/runcache/%{HTTP_HOST}/$1/index.html [L]
# Set environment variable for cached pages
RewriteCond %{REQUEST_FILENAME} /wp-content/cache/runcache/
RewriteRule .* - [E=RUNCACHE_HIT:1]
Header always set X-RunCache-Type "Apache" env=RUNCACHE_HIT
Header always set X-RunCache-Status "HIT" env=RUNCACHE_HIT
# END RunCache