# Serves Blaminhor Essentials' pre-generated HTML directly from disk WHEN POSSIBLE,
# bypassing PHP for maximum throughput. Falls back to PHP (and the advanced-cache.php
# drop-in) when any of the conditions below is not met.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Skip rewrites for admin / login / REST / xmlrpc / cron — they must reach PHP.
RewriteCond %{REQUEST_URI} !^/wp-(admin|login\.php|cron\.php) [NC]
RewriteCond %{REQUEST_URI} !^/xmlrpc\.php [NC]
RewriteCond %{REQUEST_URI} !^/wp-json/ [NC]

# GET only.
RewriteCond %{REQUEST_METHOD} ^GET$ [NC]

# No query string at all (any QS, even tracking, defeats the file-level fast path).
RewriteCond %{QUERY_STRING} ^$

# No bypass cookies.
RewriteCond %{HTTP_COOKIE} !(wordpress_logged_in_|comment_author_|wp-postpass_|woocommerce_items_in_cart|wp_woocommerce_session_|edd_items_in_cart) [NC]

# Cache file exists.
RewriteCond %{DOCUMENT_ROOT}{{CACHE_REL}}/%{HTTPS:scheme}/%{HTTP_HOST}%{REQUEST_URI}/desktop.html -f
# Serve it.
RewriteRule .* "{{CACHE_REL}}/%{HTTPS:scheme}/%{HTTP_HOST}%{REQUEST_URI}/desktop.html" [L]
</IfModule>
