> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abconvert.io/llms.txt
> Use this file to discover all available pages before exploring further.

# URL redirect tests on a custom storefront

> Send each visitor to their test group's page from your server, before the original page renders.

A [URL redirect test](/experiments/url-redirect-test) sends some visitors to a different page. On a custom storefront your server does the redirect, with the destination the SDK gives it.

**Runs on:** the server only, before the page renders. Use the client made from the request.

## Redirect on the server

On Next.js, the middleware from [the Next.js guide](/headless-sdk/nextjs#step-1-install-the-package-and-add-the-middleware) does this for you. On Hydrogen and other servers, add it to your root loader or your middleware:

```ts Server (loader or middleware) theme={null}
// Before the page renders
const destination = abconvert.getRedirectUrl(request.url);
if (destination) {
  // Keep the SDK's cookies and keep the redirect out of shared caches
  const headers = new Headers({ 'Cache-Control': 'private' });
  for (const cookie of abconvert.getSetCookieHeaders()) headers.append('Set-Cookie', cookie);
  return redirect(destination, { status: 307, headers });
}
```

Send the SDK's cookies with the redirect. Without them, a new visitor reaches the destination with no visitor ID, gets a new one, and can land in another test group there.

`getRedirectUrl` returns `null` when the visitor stays: they are in Control or outside the test, the URL is not part of a test, or the visitor is a known crawler. Redirecting on the server means the visitor never sees the original page first.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.