Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Plugin how-tos · Guide

How to Set Cloudflare Cache Rules for WordPress

Short answer

To set Cloudflare Cache Rules for WordPress, create a Bypass cache rule first for /wp-admin, /wp-login.php, /wp-json/, /wp-cron.php and logged-in cookies, then create a second rule that marks HTML as Eligible for cache for guests. Use a short Edge TTL of 2 hours, purge the cache after edits, and check the cf-cache-status header for HIT on public pages.

Key takeaways

  • Cloudflare does not cache HTML or JSON by default, so WordPress pages need a Cache Rule to be served from the edge.
  • A bypass rule for admin, login and logged-in cookies must sit above the rule that caches HTML for guests.
  • The Free plan allows 10 Cache Rules, Pro allows 25, Business allows 50 and Enterprise allows 300, as of November 2026.
  • Cloudflare only caches GET and HEAD requests, and a Set-Cookie header stops a response from being cached by default.
  • A public page that is cached shows cf-cache-status: HIT, with an Age header that grows on later requests.
  • APO is a separate WordPress option that caches HTML for 30 days and clears changed pages within 30 seconds when the plugin is installed.

What is a Cloudflare cache rule?

A Cloudflare cache rule is a setting that tells Cloudflare what to cache, what to skip, and how long to keep a copy.

Cloudflare docs say Cache Rules let you change what is eligible to cache, how long it should be cached, and where. You can create them in the dashboard, through the API, or with Terraform.

A cache rule has two parts. The first part matches requests, such as a path, a hostname, or a cookie. The second part sets the action, such as Bypass cache or Eligible for cache.

What does Cloudflare cache by default on WordPress?

Cloudflare caches static files by default, but it does not cache WordPress HTML by default.

Cloudflare docs say the CDN does not cache HTML or JSON by default. It caches by file extension, not by MIME type, and it caches a site's robots.txt by default.

That means images, CSS, and JavaScript often come from the edge, while each page view still reaches your origin. A Cache Rule is the step that changes that for HTML.

Cloudflare also skips some responses even when a rule makes them eligible. Cloudflare docs say it does not cache a resource when Cache-Control is private, no-store, no-cache, or max-age=0, when a Set-Cookie header exists, or when the method is not GET.

What do you need before you create cache rules?

You need a Cloudflare account, a domain with proxied DNS records, and admin access to WordPress.

Check that your site loads through Cloudflare first. Open a page and look for a cf-ray header in the response. If that header is missing, the request did not pass through Cloudflare, and no Cache Rule will apply.

Make a backup before you change caching. If a rule caches the wrong page, you will want a known good copy to restore. Our guide to how to back up WordPress covers the steps.

Allow about 30 minutes for the first setup. Most of that time goes to checking headers and testing logged-in and logged-out views, not to creating the rules.

How do you create a bypass rule for admin and logged-in users?

Create the bypass rule first, before any rule that caches HTML.

Follow the steps in Cloudflare docs: go to the Cache Rules page in the Cloudflare dashboard, select Create rule, enter a name, choose Custom filter expression, set Cache eligibility to Bypass cache, then select Deploy.

Step 1: Name the rule

Use a clear name such as “Bypass WordPress admin and logged-in users”. A clear name helps you find the rule later when a page behaves oddly.

Step 2: Match admin paths and login cookies

Use Custom filter expression with the fields and operators from Cloudflare docs. Match URI Path and Cookie fields with contains and starts with operators.

(http.request.uri.path contains "/wp-admin") or
(http.request.uri.path contains "/wp-login.php") or
(http.request.uri.path contains "/wp-json/") or
(http.request.uri.path contains "/wp-cron.php") or
(http.cookie contains "wordpress_logged_in")

This expression covers the admin area, the login page, the REST API, the cron endpoint, and any visitor with a logged-in cookie. Add your renamed login path if you changed it with a plugin.

Step 3: Set the action and place the rule first

Set Cache eligibility to Bypass cache. Then use the Place at control to put this rule above your HTML caching rule.

Cloudflare docs say you can select the order of your rule under Place at, and you can change the order later from the main rules page. Save the rule as a draft if you are not ready to deploy it.

How do you create a rule to cache HTML for guests?

Create a second rule that marks public HTML as Eligible for cache for visitors who are not logged in.

Go to the Cache Rules page, select Create rule, and name it “Cache HTML for guests”. Choose Custom filter expression and match your hostname with the equals operator, as shown in Cloudflare docs.

(http.host eq "example.com")

Replace example.com with your own domain. Set Cache eligibility to Eligible for cache.

This rule only works safely because the bypass rule sits above it. A logged-in visitor still matches the bypass rule, so their pages go to the origin instead of the shared cache.

Do not use this rule if your site shows different content to every visitor. Membership sites, forums, and stores with personalised pages need tighter matching, or a different caching plan.

How do you choose an Edge TTL and a Browser TTL?

Choose a short Edge TTL for HTML and a longer one for files that rarely change.

Edge TTL is how long Cloudflare keeps a copy before it asks your origin again. Cloudflare docs list 3 Edge TTL modes: follow the origin header and bypass if none is present, follow the origin header and use Cloudflare defaults if none is present, or ignore the origin header and use a TTL you set.

For WordPress HTML, pick “Ignore cache-control header and use this TTL” with 2 hours. A short TTL limits how long a stale page can be served after an edit, and you can purge sooner when needed.

Browser TTL is how long a visitor's browser keeps its own copy. Cloudflare docs say you can Bypass cache, Respect origin, or Override origin for Browser TTL. Leave it on Respect origin for HTML, so your origin headers stay in control.

A related header pattern is stale-while-revalidate. web.dev says a Cache-Control header with stale-while-revalidate should also contain max-age, and the number of seconds in max-age decides staleness.

ResponseDefault Edge TTLWhat it means
200, 206, 301120 minutesA normal page or redirect stays cached for 2 hours when no header sets a TTL
302, 30320 minutesA short redirect stays cached for 20 minutes
404, 4103 minutesA missing page stays cached for 3 minutes

The table above shows the defaults from Cloudflare docs. Those defaults apply when no cache-control or expires header is present. Your rule can override them for matched requests.

How do you handle WooCommerce carts, checkout and accounts?

Add WooCommerce paths and cookies to your bypass rule, and never cache cart, checkout, or account pages.

WooCommerce guidance says the Cart, My Account, and Checkout pages need to stay dynamic because they show information specific to the current customer. A cached cart can show one shopper's items to another shopper.

Add these conditions to the bypass expression from the earlier step:

  • URI Path contains “/cart”
  • URI Path contains “/checkout”
  • URI Path contains “/my-account”
  • Cookie contains “woocommerce_items_in_cart”
  • Cookie contains “woocommerce_cart_hash”

The cookie conditions matter as much as the paths. A shopper can carry a cart cookie on a product page, so a path-only rule would still risk serving a cached page that shows the wrong cart count.

Also bypass any URL with ?add-to-cart= in the query string. That request changes the cart, so it must reach the origin.

How do you purge the cache after you change a post?

Purge the changed URL, not the whole cache, after most edits.

In the Cloudflare dashboard, go to Caching, then Configuration, then Purge Cache, and select Custom Purge. Choose Purge by URL and enter the full address of the changed page.

Purge Everything clears all cached resources for the zone, so use it only after a theme change, a site-wide edit, or a fix that touched many pages. A full purge sends the next request for each page back to your origin.

Cloudflare docs say you can purge up to 100 prefixes per request when you purge by prefix. That option suits a section change, such as clearing every URL under /blog/.

If you use the official Cloudflare plugin, it can purge changed content for you. The plugin page on WordPress.org lists 200,000+ active installations and needs PHP 7.4 or higher, as of November 2026.

How do you check if a page is cached?

Check the cf-cache-status header in a logged-out browser window.

Open your page in a private window, open the browser developer tools, and look at the response headers for the HTML document. Cloudflare docs say the cf-cache-status header shows the cache decision Cloudflare made.

Header valueWhat it meansWhat to do
HITThe page came from the Cloudflare cacheNothing; the rule works
MISSThe page was cacheable but was not in the cache yetLoad the page again and check for HIT
DYNAMICCloudflare decided the request was not eligible for cacheCheck the rule match, the method, and Development Mode
BYPASSThe request was eligible, but the origin or config stopped storageCheck Cache-Control, Set-Cookie, and your bypass rules

A fresh HIT also shows an Age header that grows on later requests, according to Cloudflare docs. Load the page twice from the same browser to see the change.

If you see DYNAMIC on a public page, check 3 things.

First, confirm the method is GET or HEAD, because Cloudflare docs say Cloudflare only caches those 2 methods. Second, check that Development Mode is off, because it suspends cache for 3 hours and returns DYNAMIC for every response.

Third, use the Rules simulator to see which rules match the URL.

Should you use Cache Rules or APO for WordPress?

Use Cache Rules if you want free, manual control, and use APO if you want WordPress-aware HTML caching with automatic purging.

APO is Cloudflare's Automatic Platform Optimization for WordPress. The APO FAQ in Cloudflare docs says that with the WordPress plugin installed, APO caches content for 30 days and clears changed content within 30 seconds.

That 30-day TTL sounds long, but the 30-second purge is what makes it work for blogs. The plugin tells Cloudflare when a post changes, so the old copy does not stay live for a month.

APO costs $5 per month on the Free plan and is included with Pro and Business, according to the plugin page on WordPress.org, as of November 2026. Do not run APO and a manual HTML Cache Rule at the same time, because two systems can fight over the same pages.

If you compare plans first, read our Cloudflare Free vs Pro for WordPress guide.

For the wider speed picture, see how to speed up WordPress.

For costs, see how much a CDN costs for WordPress.

What mistakes should you avoid?

Avoid caching logged-in pages, long HTML TTLs, and query strings that split your cache.

First, never cache a page that sets a cookie or shows personal data. Cloudflare docs say a Set-Cookie header stops caching by default, and that is a guard, not a bug. If your rule overrides it with a fixed Edge TTL, you take that guard away.

Second, do not set a 30-day Edge TTL on HTML by hand. APO can use 30 days because it purges within 30 seconds of a change. A manual rule has no such purge link unless you set one up.

Third, watch query strings. Cloudflare docs say every unique query string is a separate cache entry by default, so session IDs, timestamps, and utm_* tags can split one page into many cache entries.

A custom cache key can ignore those parameters. The settings page in Cloudflare docs caps a custom cache key at 100 query string parameters.

Fourth, do not stack a second page cache on top of Cloudflare without a plan. A plugin cache and an edge cache can each purge on different schedules. Our WP Rocket vs host caching comparison explains how those layers interact.

Finally, check the size limits before you cache large files. Cloudflare docs say the cacheable size limit is 512 MB on Free, Pro, and Business plans, and 5 GB by default on Enterprise, as of November 2026. A file above the limit will not stay in the cache.

Plan limits also matter. Cloudflare docs list 10 Cache Rules on Free, 25 on Pro, 50 on Business, and 300 on Enterprise, as of November 2026. Keep your rules short and clear, so you do not run out of slots on a small plan.

Frequently asked questions

Do I need a Cache Rule if Cloudflare already caches my images?

No, not for images, CSS and JavaScript, because Cloudflare caches those by file extension by default. You need a Cache Rule only when you want HTML pages cached at the edge. Without one, each page view still reaches your origin, even when your static files are cached.

Why do logged-in users see a cached page?

Your bypass rule is missing or placed below the caching rule, or it does not match the logged-in cookie. Check that the bypass rule matches wordpress_logged_in cookies and the /wp-admin and /wp-login.php paths. Then load the page in a logged-in window and confirm the cf-cache-status header is not HIT.

How long should the Edge TTL be for WordPress posts?

Use 2 hours for most blogs and small sites. That is long enough to cut origin load, and short enough that a stale post does not stay live for a day. Purge the changed URL after an edit instead of waiting for the TTL to expire. News sites that update often may prefer 30 minutes.

Can I cache my WooCommerce shop pages with Cloudflare?

Yes, you can cache public shop, category and product pages for guests, as long as cart, checkout and account pages bypass the cache. Add the cart, checkout and my-account paths plus the WooCommerce cart cookies to your bypass rule. Then test a full purchase as a guest before you call the setup done.

What should I do if a page shows DYNAMIC after I add a rule?

First check that the page is a GET request and that Development Mode is off, since that mode suspends cache for 3 hours. Then use the Rules simulator to see which rules match the URL. Also check for a Set-Cookie header or a no-store Cache-Control header from your origin, because either can stop storage.

Should I use Cache Rules and APO together?

No, pick one system for HTML caching. APO already caches eligible HTML and purges changed pages within 30 seconds when the WordPress plugin is installed. Adding a manual Cache Everything rule on top can cache pages APO would skip, including logged-in or cart pages, so keep only one active.

Sources

  1. Cache Rules Cloudflare Docs
  2. Create a cache rule in the dashboard Cloudflare Docs
  3. Cache Rules settings Cloudflare Docs
  4. Default Cache Behavior Cloudflare Docs
  5. Investigate uncached responses Cloudflare Docs
  6. Automatic Platform Optimization FAQs Cloudflare Docs
  7. Cloudflare WordPress plugin WordPress.org
  8. Crawl Budget Management Google for Developers

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test