Skip to content

WordPress + Cloudflare cache rules: what actually pays off

Cloudflare Cache Rules for a WordPress site — which rules deliver measurable improvement, which are placebo, and the ordered checklist that turns a default zone into a tuned one.

A WordPress site on Cloudflare with default settings sees roughly a 30% reduction in origin traffic on a brochure-style content site, and roughly nothing on a logged-in or commerce site. The default cache rules are tuned to be safe, not effective. The Cache Rules engine (which replaced Page Rules for caching purposes in 2023) is where the real WordPress-aware tuning happens. This article documents the rules that pay off and the ones that look impressive but do not.

What’s happening

Cloudflare’s default behavior on a WordPress origin is to cache static assets aggressively and to never cache HTML unless explicitly told to. APO changes that for HTML via Workers KV, but Cache Rules can also achieve much of the same effect on a free or Pro plan without APO. The point of writing custom rules is to:

  • Cache HTML aggressively for anonymous visitors
  • Bypass cache for logged-in visitors, admin, WooCommerce dynamic endpoints
  • Normalize query strings so acquisition tracking does not fragment the cache key
  • Use longer browser TTLs on fingerprinted assets
  • Avoid caching things that look static but are not (sitemaps, RSS feeds, robots.txt)

How to verify

Confirm what is currently cached and what is not:

curl -sI https://www.example.com/ | grep -i cf-cache-status
curl -sI https://www.example.com/wp-admin/admin.php | grep -i cf-cache-status
curl -sI https://www.example.com/wp-content/themes/site/style.css | grep -i cf-cache-status
curl -sI 'https://www.example.com/?utm_source=newsletter' | grep -i cf-cache-status

A tuned setup shows HIT on the front-end HTML (anonymous), BYPASS or DYNAMIC on wp-admin, HIT on theme assets, and HIT on the front-end HTML with the UTM parameter ignored.

Check the cache analytics in the Cloudflare dashboard: Caching → Overview shows requests served from cache vs origin. A WordPress site with the rules below should sustain >85% cached requests on content-led traffic.

The fix

Apply these rules in order. Cloudflare evaluates rules top-down; the first matching rule wins.

  1. Bypass cache for wp-admin and login:

    • Match: URI Path contains "/wp-admin/" or URI Path eq "/wp-login.php"
    • Action: Bypass cache
  2. Bypass cache for WooCommerce dynamic paths:

    • Match: URI Path contains "/cart" or "/checkout" or "/my-account" or starts with "/wc-api/" or "/?wc-ajax="
    • Action: Bypass cache
  3. Bypass cache for logged-in visitors:

    • Match: any(http.request.cookies["wordpress_logged_in_*"][*] != "")
    • Action: Bypass cache
  4. Cache HTML for anonymous visitors:

    • Match: Hostname eq "www.example.com" and URI Path does not contain "/wp-admin/" and URI Path does not start with "/wp-json/"
    • Edge TTL: 1 hour. Browser TTL: respect origin (your origin’s Cache-Control should set the visitor TTL)
  5. Ignore acquisition tracking params in cache key:

    • Match: same as rule 4
    • Cache key: Ignore query string parameters matching utm_source, utm_medium, utm_campaign, utm_term, utm_content, fbclid, gclid, msclkid, yclid, _ga, mc_cid, mc_eid
  6. Force long browser TTL on fingerprinted assets:

    • Match: URI Path matches "\.(js|css|woff2|woff|ttf|png|jpg|jpeg|gif|svg|webp|avif|ico)$"
    • Edge TTL: 30 days. Browser TTL: 1 year (Cache-Control: public, max-age=31536000, immutable)
  7. Do not cache sitemap and RSS (so search engines see fresh content):

    • Match: URI Path ends with "/sitemap.xml" or "/sitemap_index.xml" or "/feed/" or "/comments/feed/"
    • Edge TTL: 5 minutes. Browser TTL: 5 minutes.
  8. Robots.txt cached short:

    • Match: URI Path eq "/robots.txt"
    • Edge TTL: 1 hour.

Skip the rules other guides recommend that do not pay off on WordPress:

  • Always Online: serves stale pages when origin is down. Sounds useful; in practice, Cloudflare’s freshness logic produces stale results so often that we leave it off.
  • Mirage: only on Pro+. Marginal improvement on already-optimized image pipelines. Often interacts badly with lazy-loading.
  • Rocket Loader: defers JavaScript globally. Breaks too many WordPress plugins to be the default. Use targeted defer/async instead.

After applying the rules, wait 24 hours and check cache analytics. The expected outcome on a WordPress content site is >85% cached, with the origin traffic chart showing a step-change drop.

Stack Harbor configures Cloudflare Cache Rules per Enterprise WordPress site and documents the rules in the site runbook. If your Cloudflare hit ratio is below 80% and you have not tuned cache rules, book a CDN audit.