Skip to main content
A 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 does this for you. On Hydrogen and other servers, add it to your root loader or your middleware:
Server (loader or middleware)
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.