This site is not affiliated with or endorsed by Cloudflare, Inc. It showcases deployable experiments across most Cloudflare products.
Network & Monitoring

Edge Redirect Simulator

Follow and report full HTTP redirect chains from Cloudflare's edge - every hop, status code, and final URL

Show redirect chains for any URL from Cloudflare's edge. The Worker follows HTTP redirects (301, 302, 303, 307, 308) and returns each hop with its status code, so you can see exactly how a URL resolves.

API Reference

GET /redirect-chain

Follow redirects for a URL and return the chain of hops.

Prop

Type

Example Request

curl "https://your-worker.workers.dev/redirect-chain?url=https://example.com"

Success Response

chain array

Array of objects, one per hop in the redirect chain.

url string

The URL at this hop (after redirect, if any).

status number

HTTP status code at this hop (e.g. 301, 302, 200).

error string (optional)

Present if the chain was truncated-e.g. missing Location header, redirect loop, or max redirects exceeded. Response is still 200 with the chain collected so far.

Example Response

{
  "chain": [
    { "url": "https://example.com/", "status": 301 },
    { "url": "https://www.example.com/", "status": 302 },
    { "url": "https://final.example.com/", "status": 200 }
  ]
}

Display form: example.com → 301 → www.example.com → 302 → final.example.com → 200.

Error Responses

400 Bad Request - Missing or invalid url (wrong scheme or malformed):

{
  "error": "Missing or invalid query parameter: url",
  "code": "INVALID_URL"
}

500 Internal Server Error - Uncaught error (e.g. fetch failure):

{
  "error": "Internal error message",
  "code": "INTERNAL_ERROR"
}

If the chain hits a redirect with no Location or exceeds the hop limit, the response is still 200 with the chain collected so far and an error message in the body.

Use Cases

  • Debug redirects - See the full chain from short URL or vanity domain to final destination
  • SEO and canonicalization - Verify 301/302 chains and final URLs
  • Security and compliance - Audit where redirects lead before clicking
  • Integration testing - Confirm redirect behavior from the edge

Limitations

  • Stops after 20 redirects to prevent infinite loops
  • Does not follow meta refresh or JavaScript-based redirects
  • Fetch timeout applies per hop on slow origins
  • Reports redirect chain from the edge; results may differ from a browser

Use in your project

Copy these files into an existing Worker. Prefer Deployment to try the full experiment first. Source: apps/experiments/edge-redirect-simulator.

DependenciesNoneBindingsNonePlatformFetch API
import type { RedirectChainStep } from "../types/redirect-chain";import { MAX_REDIRECTS, REDIRECT_STATUS_CODES } from "../constants/defaults";const REDIRECT_SET = new Set<number>(REDIRECT_STATUS_CODES);function isRedirect(status: number): boolean {  return REDIRECT_SET.has(status);}function resolveNextUrl(currentUrl: string, location: string): string {  try {    return new URL(location, currentUrl).href;  } catch {    return "";  }}/** * Follows redirects manually and returns each hop (url + status). * Uses redirect: 'manual' so we capture every response. */export async function getRedirectChain(  initialUrl: string): Promise<{ chain: RedirectChainStep[]; error?: string }> {  const chain: RedirectChainStep[] = [];  let url: string = initialUrl;  let hops = 0;  while (hops <= MAX_REDIRECTS) {    const res = await fetch(url, {      redirect: "manual",      headers: { "User-Agent": "Edge-Redirect-Simulator/1.0" },    });    chain.push({ url, status: res.status });    if (!isRedirect(res.status)) {      return { chain };    }    const location = res.headers.get("Location");    if (!location || !location.trim()) {      return { chain, error: "Redirect response missing Location header" };    }    const nextUrl = resolveNextUrl(url, location.trim());    if (!nextUrl || nextUrl === url) {      return { chain, error: "Invalid or circular Location header" };    }    url = nextUrl;    hops++;  }  return {    chain,    error: `Max redirects (${MAX_REDIRECTS}) exceeded; possible redirect loop`,  };}

Deployment

Click the deploy button

Deploy to Cloudflare Workers

Deploy

Follow the deployment wizard to deploy the Worker to your Cloudflare account. No additional configuration or bindings required.

Test your deployment

curl "https://your-worker.workers.dev/redirect-chain?url=https://cloudflare.com"

Local Development

cd apps/experiments/edge-redirect-simulator
npm install
npm run dev

Then open: http://localhost:8787/redirect-chain?url=https://cloudflare.com

Cloudflare Features Used

  • Workers - Edge compute runtime
  • Fetch API - HTTP requests with redirect: "manual" to capture each hop
  • Edge network - Redirect chain observed from Cloudflare's global network

Next Steps

On this page