Presence of query string make route match fail

I have a worker that changes the origin for a few routes on our homepage to point to our new marketing site. The routes similar following:

https://disclosures.io/product/*

When I navigate to the root without query string params the worker is activated correctly. However, if a query string such as a utm value is present (i.e. (HLM) HomeLight Listing Management | On-market to offer accepted, faster! - Sign Up Now (It's free!) HomeLight Listing Management) the route match no longer works.

Is this a bug or am I doing something wrong?

I have query string params on my workers and they work fine.
Maybe the worker code:
try adding route, if it doesn’t work can you add part of your code here.
https://disclosures.io/?*

1 Like

I get the following error when trying to add query string params.

Route pattern should not have query parameters (HLM) HomeLight Listing Management | On-market to offer accepted, faster! - Sign Up Now (It's free!) HomeLight Listing Management*

I should also note that query strings work with my wildcard rule under the product directory. It seems like something about matching the root path exactly.

My worker code is the following:

addEventListener('fetch', event => {
  const request = event.request
  const url = new URL(event.request.url)

  if (url.hostname === 'stage.disclosures.io') {
    url.hostname = 'disclosures-stage.netlify.com'
  }
  
  if (url.hostname === 'disclosures.io' || url.hostname === 'www.disclosures.io') {
    url.hostname = 'disclosures-prod.netlify.com'
  }
  
  const args = {
    method: request.method,
    headers: request.headers
  }

  if (request.method === 'PUT' || 'POST') {
    args.body = request.body
  }
  return event.respondWith(fetch(new Request(url, args)))
})

Hi played here:
https://Cloudflareworkers.com/#aafee41f010f958c1d06bea3c6f97efa:https://disclosures.io/?utm=campaign

maybe route:
https://disclosures.io/*

1 Like

This is accurate and useful when you have other routes such as:

domain.com/linkworkerA?parameter=abc assigned to workerA then your route needs to be configured as domain.com/linkworkerA*

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