Route to a Workers script only when a query string exists?

We have a cost-minded use case where we need to serve a path (without query string) directly from Cloudflare’s CDN cache, and to serve that same path (with query string) from a Workers script.

I haven’t yet found a way to avoid Workers when there’s no query string.

What we need/expect is:  -> <no script>* -> worker-script

In the Cloudflare Workers UI we have Workers disabled on the route, and enabled on*

But still routes to Workers.

I’m aware that the * wildcard operator matches zero or more of any character, but was hoping disabling Workers on would take precedence over*. It’s arguable, but I feel that’s in the spirit of the Routes doc:

When more than one route pattern could match a request URL, the most specific route pattern wins.

Perhaps someday ?* could be supported to denote a query string.

Given the same path, is there someway to route to a Workers script only when a query string exists?

Workers routes don’t pay attention to Query strings.

1 Like

Thanks for confirming and linking to that prior topic.

Workaround: Since a Page Rules URL pattern can handle query strings, I set a Page Rule to forward* to$1 with a Workers route of*. This lets serve from the CDN.

Letting hit the Workers script would have been unnecessarily expensive, to the tune of thousands of U.S. dollars per month. I can see my workaround not working for other sites’ URL structures, so consider this a feature request for query string awareness in Workers routes.

1 Like