How To Use Cloudflare Cache Everything AND Ignore Query Strings

How To Use Cloudflare Cache Everything AND Ignore Query Strings

  1. Home
  2. Knowledge Base
  3. How To Use Cloudflare Cache Everything AND Ignore Query Strings

We came across a site speed issue recently where a customer was using Cloudflare Cache Everything rules to cache HTML at the edge and also had a significant portion of paid traffic, multiple 7 figures per year.

This was a problem as Cloudflare interprets each URL with a query string as unique therefore these pages didn’t exist in the edge cache and had to be fetched from the origin from scratch.

On top of that, some of these query strings were unique and also bypassing cache on the origin where we had little control due to an obscure CMS.

This meant those paid traffic landing pages were extremely slow to load, with super high TTFB, and were failing Google Core Web Vitals. This also meant our most expensive traffic was getting the worst speed experience which was definitely impacting conversions.

In Cloudflare Page Rules, you cannot use Cache Level “Cache Everything” AND “Ignore Query Strings” so that was not a fix.

The Issue Is Not As Prevalent With Cloudflare APO

If you’re using Cloudflare APO for edge caching this problem can be easily fixed using a Cache Level:Ignore Query Strings rule because the APO feature drives the edge caching.

APO also ignores popular query strings so the issue is not as prevalent – list of those query strings is here.

The Solution Is Transform Rules

With Cloudflare Transform Rules you can fix this problem. The screenshot below details the transform rule we used to fix this issue. Note that you’ll need to add query strings used by all traffic sources in order for this rule to fully work.

Cloudflare Transform Rules Can Be Used To Cache Everything And Ignore Query Strings (Click To Enlarge)

Copy/Paste Version Of This Rule

Here’s the raw expression code you can use to copy and paste this into your own Cloudflare account.

This copy/paste rule also ignores query strings for Google UTM tracking strings, which are also subject to the same problem with a “cache everything” rule, along with all the other popular query strings Cloudflare APO automatically ignores as well as Callrail tracking strings which many of our customers use for call tracking and form attribution and also Tiktok ads (?ttclid).

To use this code, add a new transform rule and then click Edit Expression and copy paste in the rule.

(http.request.uri.query contains "camp") or (http.request.uri.query contains "vgo_ee") or (http.request.uri.query contains "msclkid") or (http.request.uri.query contains "fbclid") or (http.request.uri.query contains "utm_") or (http.request.uri.query contains "ref") or (http.request.uri.query contains "mc_") or (http.request.uri.query contains "gclid") or (http.request.uri.query contains "fb_") or (http.request.uri.query contains "_ga") or (http.request.uri.query contains "ttclid") or (http.request.uri.query contains "mkt_tok") or (http.request.uri.query contains "epik") or (http.request.uri.query contains "dclid") or (http.request.uri.query contains "campaignid") or (http.request.uri.query contains "adgroupid") or (http.request.uri.query contains "_ke") or (http.request.uri.query contains "creative") or (http.request.uri.query contains "matchtype") or (http.request.uri.query contains "device") or (http.request.uri.query contains "network") or (http.request.uri.query contains "keyword")

Was this article helpful?