# Edge Redirect Simulator (/docs/experiments/edge-redirect-simulator)



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 [#api-reference]

### GET /redirect-chain [#get-redirect-chain]

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

<TypeTable
  type="{
  url: {
    description:
      &#x22;The URL to trace. Use a full URL (`https://cloudflare.com`) or hostname (`example.com`). Only `http` and `https` are allowed.&#x22;,
    type: &#x22;string&#x22;,
    required: true,
  },
}"
/>

#### Example Request [#example-request]

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

#### Success Response [#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 [#example-response]

```json
{
  "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 [#error-responses]

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

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

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

```json
{
  "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 [#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 [#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

## Deployment [#deployment]

<Steps>
  <Step>
    ### Click the deploy button [#click-the-deploy-button]

    [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shrinathsnayak/cloudflare-experiments/tree/main/apps/experiments/edge-redirect-simulator)
  </Step>

  <Step>
    ### Deploy [#deploy]

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

  <Step>
    ### Test your deployment [#test-your-deployment]

    ```bash
    curl "https://your-worker.workers.dev/redirect-chain?url=https://cloudflare.com"
    ```
  </Step>
</Steps>

## Local Development [#local-development]

```bash
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 [#cloudflare-features-used]

* **[Workers](https://developers.cloudflare.com/workers/)** - Edge compute runtime
* **[Fetch API](https://developers.cloudflare.com/workers/runtime-apis/fetch/)** - HTTP requests with `redirect: "manual"` to capture each hop
* **[Edge network](https://developers.cloudflare.com/workers/reference/how-workers-works/)** - Redirect chain observed from Cloudflare's global network

## Next Steps [#next-steps]

<Cards>
  <Card title="Is It Down?" href="/experiments/is-it-down">
    Check if a website is reachable from the edge
  </Card>

  <Card title="URL DNS Lookup" href="/experiments/url-dns-lookup">
    Get DNS records for any URL's hostname
  </Card>

  <Card title="GitHub Repository" href="https://github.com/shrinathsnayak/cloudflare-experiments/tree/main/apps/experiments/edge-redirect-simulator">
    View the complete source code
  </Card>

  <Card title="More Experiments" href="/">
    Explore other Cloudflare experiments
  </Card>
</Cards>
