Ignore GET parameters with cache everything


Hi, I’m wondering if it’s possible with Cloudflare Workers to ignore certain GET parameters with cache everything.

For example, the following three pages would all be in the same cache, with mkt_tok being ignored:



If I got the question right the solution is to basically rewrite the URL without the parameters. Then perform the request to the new URL which would pass through the cache (the worker is in front of the cache).


addEventListener('fetch', event => {
async function fetchAndChange(request) {
  var url = new URL(request.url)

  // modify URL as you wish
  // newURL is the modified URL

  var newRequest = new Request(newURL, request)
  return fetch(newRequest)


You can set your Caching Level to Ignore Query String.


Awesome, thanks for the help! I’ve got it working now.


This wouldn’t work because the “ignore query string” cache level only applies to images, etc. It wouldn’t apply to real pages. Matteo’s solution worked for me.


If it helped and the problem was solved, would you mind accepting it as a solution (so I am happy :blush: and others come looking for an answer and not looking to help you when it’s not needed)?


Yes, I didn’t realize you could do that here. Done!


Here’s my goal:

I created this worker:

addEventListener('fetch', event => {

async function handle(request) {
  let newUrl = myRewriteFunction(request.url)
  let response = await fetch(newUrl, request)

  // Copy the response so that we can modify headers.
  response = new Response(response.body, response)

  // Shove our rewritten URL into a header to find out what it was.
  response.headers.set("X-Debug", newUrl)

  return response

function myRewriteFunction(url) {
  n = url.indexOf('?');
  url = url.substring(0, n != -1 ? n : url.length);
  return url

This still seems to “miss” cache on each initial request for the same base URL with a different token. Any suggestions?


@matteo’s worker based solution will do the job here.

I want to highlight for the other readers that @hklcf’s suggestion to set the Caching Level to Ignore Query String will also achieve the same outcome.

You can also use Page Rules to target this setting to only some parts of your website.