How a Cloudflare Worker Can Consolidate Duplicate URLs Into One Canonical Link
A developer managing a static site found that Google Search Console had indexed multiple legacy URL variants of the same pages, including HTTP, WWW, and index.html versions. To fix this, they built a Cloudflare Worker that normalizes protocol, hostname, and path in a single redirect step, avoiding multi-hop redirect chains. The Worker uses an explicit map of legacy paths to their canonical equivalents, ensuring only known redirects are applied rather than blindly routing all unknown URLs to the homepage. Configuration requires the Worker to intercept requests before static assets are served, using Cloudflare's run_worker_first setting. The approach is reinforced with self-referencing canonical tags and a clean XML sitemap to send consistent signals to search engine crawlers.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in