Tutorial

Consolidate two domains with one Cloudflare Worker.

You have a legacy site on one host and a shiny new one on another. Marketing wants everything under www.example.com. SEO won't survive a hard cutover. A reverse proxy in front of both origins, deployed as a Cloudflare Worker, fixes this in about 80 lines of JavaScript. This walkthrough builds one with you.

What you'll have when you're done

Steps

  1. The problem
    Two domains, one brand. Why a reverse proxy beats a 301.
  2. Origins & routing
    Pick a canonical host, define origins, route by path.
  3. URL rewrites
    Rewrite canonical, hreflang, og:url, and JSON-LD back to the canonical host.
  4. Headers & CSP
    What to strip, what to forward, and how CSP breaks proxies.
  5. Redirects
    When to 301 instead of proxy, and how to keep the canonical host.
  6. Deploy
    wrangler.toml routes, custom domain, robots.txt pointer.
Each step ships with a live request simulator: change the rules, paste a URL, and see exactly what the Worker would do. No network calls — the same logic runs in your browser.