Free auditStart free
GuideSvelteKit · URL changes

SvelteKit redirects

Use SvelteKit’s server-side redirect helper for moved routes, choose a status based on whether the move is permanent, and verify the deployed response.

3 min
read
6
sources
Oct 24, 2026
updated
Scaplet Editorial Team
author
In one line

In SvelteKit, import redirect from @sveltejs/kit and call it during request handling, for example in a server load function. Use 308 when the URL has moved for good, and 307 when it may return. Don't catch the thrown redirect, and check the deployed response for the expected status and Location.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Checklist

Redirect from server-side request handling

SvelteKit’s docs say that when redirect is called during request handling, SvelteKit returns a redirect response, and that you must make sure you are not catching the thrown redirect. In load functions, don’t call it inside a try {...} block, because the redirect will immediately trigger the catch statement. Since SvelteKit 2 you call redirect(...) directly and don’t throw it. The example uses 308 for a permanent path change; use a real old-to-new map rather than deriving a destination from untrusted input.
  1. 01Use 301 or 308 for a permanent move. SvelteKit’s docs say a 308 keeps the request method and that “SEO will be transferred to the new page”. Google lists both 301 and 308 as permanent redirects, which show the new target in search results.
  2. 02Use 302 or 307 for a temporary move. SvelteKit’s docs say 307 keeps the request method. Google says temporary redirects show the source page in search results.
  3. 03Use 303 to redirect as a GET request, often after a form POST. Google groups 303 with the temporary redirects.
  4. 04For an external destination, SvelteKit 3 requires the external option, either true or an array of allowed origins, for example redirect(307, 'https://example.com', { external: true }). Prefer the array of allowed origins when you know the destinations.
src/routes/old-guide/+page.server.ts
import { redirect } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'

export const load: PageServerLoad = () => {
  redirect(308, '/guides/current-guide')
}
03How it works

Test the production result

  1. 1

    Request the old URL

    Use curl -I https://example.com/old-path against the deployed site and inspect the status and Location header.

  2. 2

    Follow the redirect

    Use curl -IL to check every hop. The chain should end at a successful page, not a loop or another redirect.

  3. 3

    Check the destination

    Confirm it is the intended page, has a self-consistent canonical, and returns the expected language or path variant.

  4. 4

    Update links and sitemap

    Change internal links and sitemap entries to the final URL so visitors and crawlers do not repeatedly traverse old paths.

For related URL signals, read canonical URLs, redirect chains, and 301 redirects. A redirect status can be lost when a reverse proxy, CDN rule, or static hosting configuration overrides the framework output, so capture response headers from the public domain after each deployment.

Sources · 6

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • svelte.dev
  • google.com
  1. 01Load functions: Redirects | SvelteKit Docssvelte.dev · checked 2026-10-24
  2. 02@sveltejs/kit: redirect | SvelteKit Docssvelte.dev · checked 2026-10-24
  3. 03Migrating to SvelteKit v3: external redirects | Svelte Docssvelte.dev · checked 2026-10-24
  4. 04Migrating to SvelteKit v2: redirect and error are no longer thrown by you | Svelte Docssvelte.dev · checked 2026-10-24
  5. 05Redirects and Google Search | Google Search Centraldevelopers.google.com · checked 2026-10-24
  6. 06Website testing and Google Search | Google Search Centraldevelopers.google.com · checked 2026-10-24
Questions

Asked a lot.

3 questions people ask next, answered from the sources on this page.

01How do I redirect a route in SvelteKit?

Import redirect from @sveltejs/kit and call it in a server load function, for example redirect(308, '/new-path'). SvelteKit handles the thrown redirect as long as you don’t catch it.

02Should I use 301 or 308 in SvelteKit?

Google treats both as permanent. SvelteKit’s docs list 308 as a common code that keeps the request method; 301 is also accepted by redirect. Test the deployed response either way.

03Can SvelteKit redirects work on a static site?

A static file cannot run redirect per request. SvelteKit’s adapter API exposes redirects found during prerendering, but check what your adapter does and verify the response with curl -I.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane