# The 301 that redirected to itself

> Moving this site to its own domain produced a redirect loop on /en. Workers Cache keys a response by its path, not its host, so a cached redirect from the old address was served on the new one.

Source: https://ouzx.me/blog/the-301-that-redirected-to-itself  
Published: 2026-11-13T10:36:15.471Z  
Updated: 2026-11-13T10:34:49.045Z

---

On 20 October 2026 this site moved from its workers.dev address to ouzx.me. The old address had to keep working, so the web Worker answers page requests on the workers.dev host with a permanent redirect to the same path on the new domain.

Soon after, `ouzx.me/en` was redirecting to itself.
## What happened

Pages are cached in the web Worker's own Workers Cache, and its cache key is the path and the query string. The host is not part of it.

1. A request reached the old address at `/en`.
2. The Worker answered `301` with `Location: https://ouzx.me/en`, and the cache stored that response under `/en`.
3. A request for `ouzx.me/en` reached the same Worker, and the cache answered first, with the stored redirect to the URL that had just been requested.

Once you know it, the symptom is easy to spot: `cf-cache-status: HIT` on a 301 whose `location` is the URL you asked for.
## The fix

A cache that does not key by host must never store a redirect between hosts. The redirect now says so itself:

```ts
if (c.env.WORKERS_DEV_HOST &amp;&amp; url.hostname === c.env.WORKERS_DEV_HOST) {
  // Never cached: Workers Cache keys by path alone, so a cached redirect would loop the domain.
  c.header("cache-control", "private, no-store");
  return c.redirect(new URL(`${url.pathname}${url.search}`, siteUrl), 301);
}
```

The fix went into [Orkide](/en/portfolio/orkide), the template this site is built on, so every product that moves to its own domain gets it ([commit 91d8c8f](https://github.com/Ouzx/orkide/commit/91d8c8f)).
## Clearing what the cache already holds

Two facts about Workers Cache decide how to get rid of a bad entry:

- **A new Worker version starts with an empty cache.** Deploying the fix started one, and the stored redirect went with the old version.
- **A zone purge does not reach it.** The cache belongs to the Worker, not to the zone.

The same applies whenever content changes outside the admin. The admin purges the cache tags of whatever it saves, but a row written straight into D1 purges nothing. Redeploying, even a Workers Builds run of the same commit, is then the quickest way to drop stale pages.
## One more account-wide limit

The third site on the same Cloudflare account failed to deploy because the Workers Free plan allows five cron triggers per account, and each product had two. Orkide now runs one trigger per product, every five minutes, and does its daily rollup on the 00:15 UTC tick.
