Cloudflare origin cache control to cache requests ignoring query strings

Is it possible to use origin cache control, to make cloudflare cache a request ignoring specific query strings I want to?

like say I have

?username=xxx&string2=yyy&string3=wwww&string4=zzzz

I want to return the same response to this URL regardless of the string username,string2.

Not sure whether it works, but you can try:

I tried to use a rule like this, with Cache Level = ignore query string + origin cache control turned on.

I made the requests have cache control = public, max-age=7200, but cloudflare is still not caching it :frowning:

You’d have to use Cloudflare Transform rules to rewrite the query string segment of the URL to strip the query strings from what Cloudflare will evaluate as the URL path https://developers.cloudflare.com/rules/transform

see some examples at https://developers.cloudflare.com/rules/transform/url-rewrite/examples

closest example would be https://developers.cloudflare.com/rules/transform/url-rewrite/examples#rewrite-url-query-string-of-blog-visitors but instead of rewriting query string to static ?sort-by=date, you’d just rewrite to static and set the field empty. So preserve the intended path but rewrite static the query string. With the document example then requests to /blog/?querystring would be evaluated by Cloudflare and transformed to /blog/

That’s what I do on my forums and Wordpress sites but I target a list of known bad ASNs and specific cookies or absence of specific cookies so that such Cloudflare Transform rules to strip query strings only apply to guest visitors and not logged in visitors.

Using a Cloudflare Transform rule allows you finer control of when it should be used i.e. you can set criteria by ASNs, country, hostname, continent, IP source, refer, request method, cookies, user agent and even query strings you can include/exclude from the transform process.

Then once you transformed the URL, set a page rule to cache everything and edge cache TTLs set it to cache duration you desire. So cache /blog/ url

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.