“One domain, several origins” is where non-Enterprise Cloudflare zones hit their first real plan wall. Splitting by hostname is free and clean: every DNS record is its own origin. Splitting by path is the hard case, because the two features built for it — Host header override and DNS record (resolve) override in Origin Rules — are Enterprise-only. Below Enterprise you have three honest tools: per-subdomain origins, a Worker acting as router, and Cloudflare Tunnel ingress rules. Between them they cover almost every real requirement, if you accept their shapes.
What’s happening
For each incoming request, Cloudflare connects to whatever the matching DNS record points at, preserving the original Host header. That single sentence contains both the freedom and the wall. Freedom: app.example.com can be an A record to a VPS, api.example.com a CNAME to a PaaS, www.example.com a record to your load balancer — three origins, zero extra cost, each with its own cache and WAF context. Wall: www.example.com/api/ connects to the www origin, full stop. Changing where a request goes based on its path, at the edge, without running code, is exactly what Origin Rules’ Host header and DNS record overrides do — and both sit behind the Enterprise plan. (Destination port override, by contrast, is available on all plans.)
The non-Enterprise workarounds move the routing decision elsewhere. A Worker mounted on the path makes the decision in code and fetches whichever origin it likes. A Tunnel makes the decision in the cloudflared connector’s ingress rules, which map hostnames and paths to different local services. Or your own reverse proxy behind a single record makes the decision on your hardware, with Cloudflare unaware anything happened.
One more boundary worth naming: none of this is failover. Steering traffic away from a dead origin automatically is the job of the paid Load Balancing add-on, on any plan — DNS records and Workers do not health-check anything by themselves.
What to check first
- Whether the split can be by hostname.
api.example.cominstead ofwww.example.com/api/dissolves the whole problem for zero dollars. CORS and cookie scope are the usual objections; both are solvable more cheaply than an Enterprise contract. - Where the origins live. Same private network: your own reverse proxy or one Tunnel with ingress rules covers it. Scattered across providers: Workers routing is the fit.
- Traffic volume through the routed paths. Workers are priced per request; at high volume, do the arithmetic before committing the architecture.
How to verify
Confirm what each hostname resolves to and which origin actually answers:
# Each subdomain is its own origin — verify the mapping
dig +short app.example.com
dig +short api.example.com
# Which origin served this? Tag responses at each origin, then:
curl -sI https://www.example.com/ | grep -i x-served-by
curl -sI https://www.example.com/api/health | grep -i x-served-by
# Is a Worker in the path? Look for the route
curl -s -H "Authorization: Bearer <api-token>" \
"https://api.cloudflare.com/client/v4/zones/<zone-id>/workers/routes"
A small X-Served-By: origin-a header set by each origin turns every routing question into a one-line curl instead of a log-diving session.
The runbook
-
Default to per-subdomain origins. One proxied DNS record per origin, each origin firewalled to Cloudflare ranges, each hostname getting its own cache and rule context. This is the boring answer and the right one for most splits: app, api, docs, status.
-
Use a Worker as the path router when the URL must not change. Mount it on the route (
www.example.com/api/*) and fetch the real origin by absolute URL:export default { async fetch(request) { const url = new URL(request.url); if (url.pathname.startsWith('/api/')) { return fetch('https://api-origin.example.net' + url.pathname + url.search, request); } return fetch(request); } };The target hostname must be resolvable and reachable from Cloudflare — a proxied record in your zone or any public hostname. Getting a first Worker deployed on a route is covered in Workers: first script and routes.
-
Use Tunnel ingress rules when origins share a network. One
cloudflaredconnector, several services: ingress rules map hostname (and path) tohttp://localhost:3000,http://10.0.0.7:8080, and so on. No inbound ports, no allowlist maintenance — the pattern is laid out in exposing a private origin with Cloudflare Tunnel. -
Or route behind one record with your own proxy. A single origin running Nginx or HAProxy that fans out internally. Cloudflare sees one origin; you own the routing table. This trades edge features for total control and is often the cleanest migration bridge for legacy paths.
-
Write down what would still require Enterprise. Path-based origin switching with Host header rewrite, purely in configuration, at the edge — that is the Enterprise Origin Rules feature set. If the workaround inventory above covers you, note it; if not, you have a priced decision, not a mystery.
When this approach is wrong
If what you actually need is health-based failover between identical origins, stop building routers — that is the Load Balancing add-on’s job, and the managed-vs-self-hosted trade-off is a separate decision. If a Worker would just proxy 100% of traffic to one origin with no logic, delete the idea; you are paying per request to do what a DNS record does free. And if the path split exists only because two teams cannot agree on a subdomain, that is an organizational problem wearing an architecture costume.
Common mistakes
- Building the Worker router before trying a subdomain. The cheapest routing layer is the one that does not exist.
- Fetching a grey-clouded hostname in your own zone from a Worker and being surprised the request bypasses Cloudflare features — subrequests follow the DNS you configured.
- Forgetting the Host header when the target origin is a shared platform. Many PaaS origins route by Host; when fetching by absolute URL, the fetch uses the target’s hostname — confirm the platform expects that name, or set headers explicitly.
- Leaving the secondary origins open to the world. Every origin in the pattern needs the same firewall allowlisting as the primary.
- Expecting the Worker to notice a dead origin. It will happily 502 forever; failover is the LB add-on or your own logic with timeouts and a fallback fetch.
Prevention / maintenance checklist
- Routing map (hostname or path, origin, mechanism) kept in the repo next to the Worker code or Tunnel config.
X-Served-Bystyle origin tags on every origin, verified quarterly with the curl checks above.- Worker request volume and cost reviewed quarterly against the subdomain alternative.
- Each origin’s firewall and certificate posture audited on the same cycle as the primary.
- Plan-gating assumptions re-checked yearly against developers.cloudflare.com/fundamentals/ — feature boundaries move, usually in your favour.
A Cloudflare migration with a written rollback plan, or a zone that gets reviewed quarterly instead of drifting — that is the operating discipline Stack Harbor sells under Managed Cloud Ops; book an infrastructure review.