How to exclude specific subdomains (like api and id) from triggering a Worker?
Hi everyone,
I’m trying to configure my Cloudflare Worker so that it runs on all subdomains of my domain (*.mydomain.com) except for a couple of specific subdomains — namely apimydomain.com and id.mydomain.com. For these two subdomains, I want the Worker not to be invoked at all.
I’ve tried:
Using route patterns in wrangler.toml/wrangler.jsonc with empty script fields for those subdomains, but I get errors.
Using _routes.json with exclude patterns, but it doesn’t seem to prevent invocation.
Listing all allowed subdomains explicitly — but this is difficult because there are many dynamic subdomains.
Does Cloudflare Workers routing support excluding subdomains from a wildcard route? If not, what’s the best practice to achieve this? Should I handle this logic inside the Worker code itself by checking the hostname and skipping processing?
Thanks in advance for your help!
3 Replies
Please do not post your question in multiple channels/post it multiple times per the rules at #😃welcome-and-rules. It creates confusion for people trying to help you and doesn't get your issue or question solved any faster.
Manually listing every other subdomain isn’t practical since they’re dynamic.
Is there a clean way to exclude just "api" and "id" subdomains while catching everything else with a wildcard?
sorry about the crosspost! Won’t happen again — just wanted to make sure it reached the right place.
Ahh, I get it now. I misunderstood earlier. Thanks for the help!
@Leo @Chaika