# Redirect experiments

A redirect experiment tests whole pages: visitors who match a path are sent to a different URL per variant. No component code is involved, so it works for a redesign, a new landing page, a different checkout flow, or two pages built in a no-code tool.

```ts
'landing': {
  kind: 'redirect',
  status: 'running',
  goal: 'signup',
  match: '/',
  variants: {
    control: { weight: 50, to: '/' },
    'new-landing': { weight: 50, to: '/start' },
  },
}
```

`match` is a path, exact or a prefix with a trailing `*` (`/pricing*`). `to` is the destination per variant; the control usually points at the matched page itself. Use same-site paths for Next.js middleware rewrites. The drop-in script and short links can navigate to absolute URLs on another host.

## Three ways to serve it

| Where | How | Flash |
|---|---|---|
| Next.js | `splithubMiddleware` rewrites the request at the edge; the address bar keeps the original URL | none |
| Drop-in script | `sh.js` assigns and navigates; put `<meta name="splithub-experiment" content="landing">` before the script | rendering held for up to 1,500 ms by default |
| Short links | a SplitHub link with two weighted destinations (no config needed) | a 302, like any short link |

A draft redirect is served in development when the config has `runDraftsInDev: true`, by the middleware and by the script alike. `?sh_force=landing:new-landing` previews one destination of a running experiment.

## Creating one

From the CLI: `npx splithub create --kind redirect --id landing --variants control,new-landing --match / --to control=/ --to new-landing=/start --goal signup --yes`.

From the dashboard: New experiment → Redirect. It asks for the page to test and the variant pages, and offers "create with a link" for the short-link variant. Experiments created there are cloud-only until `npx splithub pull` writes them into the file.

## Goals on the destination pages

The goal has to fire on the page the visitor lands on. A `pageview` goal with `path: '/thanks'` works everywhere. With the script, `click` goals bind on any page; `event` goals need `splithub.track('…')` on the destination. The visitor id is in the first-party cookie, so attribution crosses pages on the same site. Cookies are not shared across unrelated domains, and the SDK does not import visitor ids from `?sh_vid=`. Cross-domain conversion attribution needs a custom identity integration; short-link click stats work independently.

## Pitfalls

- Caching: a CDN that caches the HTML of `/` for everyone cannot serve per-visitor redirects. The middleware route and the script both run per visitor; make sure the matched page is not fully static-cached, or use the script.
- Loops: do not match the destination path of a variant with the same experiment (`match: '/start*'` while `to: '/start'`).
- Crawlers: assignment does not automatically force the control for bots. Configure crawler handling separately if a stable crawlable page is required.
