Free auditStart free
GuideSanity · Redirects

Sanity redirects

Model redirects as Sanity documents with validation, feed them to Next.js or Astro, and avoid the 301 versus 308 and redeploy surprises.

3 min
read
6
sources
Nov 1, 2026
updated
Scaplet Editorial Team
author
In one line

Sanity stores redirects as ordinary documents; your framework applies them. Create a redirect document type with source, destination and permanent, validate the paths, query it with GROQ, and return the result from your framework's redirect config. In Next.js a permanent redirect sends 308, not 301, and config redirects need a redeploy to change.

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
02Fix it on your stack

Schema, query and Next.js config

Validation from Sanity's course (trimmed)
function isValidInternalPath(value: string | undefined) {
  if (!value) return 'Value is required'
  else if (!value.startsWith('/')) return 'Internal paths must start with /'
  return true
}

defineField({
  name: 'source',
  type: 'string',
  validation: (Rule) => Rule.required().custom(isValidInternalPath),
}),
defineField({ name: 'permanent', type: 'boolean', initialValue: true }),
defineField({ name: 'isEnabled', type: 'boolean', initialValue: true })
Query
*[_type == "redirect" && isEnabled == true] {
  source,
  destination,
  permanent
}
next.config.ts
import { fetchRedirects } from '@/sanity/lib/fetchRedirects'

const nextConfig: NextConfig = {
  async redirects() {
    return await fetchRedirects()
  },
}
export default nextConfig

The course's full validator also rejects invalid characters, checks : parameter use, and blocks a rule whose source equals its destination. It states why: "invalid redirects can break future builds", and an author could publish a redirect that stops your app deploying or creates a circular loop.

For Astro, the developer guide places redirects in astro.config and notes Astro only needs a key and value pair, so a from and to pair works.

03Worth knowing

Surprises worth knowing

The comment says 301; Next.js sends 308

The course describes permanent as "permanent (301) or temporary (302)". The Next.js docs say permanent: true uses 308 and permanent: false uses 307. Both permanent codes tell search engines the move is permanent; Google's documentation names 301 and 308 together. Test the real status, do not trust the field description.

Config redirects are not live

The course says redirects in next.config.ts apply at build time and you may need to redeploy after adding or changing one. An editor who publishes a redirect in Studio has not fixed the URL until your pipeline rebuilds.

1,024 is a ceiling

The course says Vercel has a limit of 1,024 redirects in Next.js config and advises custom middleware beyond about 1,000. Vercel's own redirects page lists bulk redirects for large lists and middleware for "Dynamic redirects that need to update without redeploying."

Chains and loops

Sanity's guide says to avoid chains and to modify a chained redirect so it goes from A to B directly. Google also advises redirecting to the final destination.

Fix the links

The guide says to update old internal links rather than lean on the redirect.

04How it works

Check it worked

  1. 1

    Request the old URL

    Run curl -sI https://www.example.com/old-path. Expect one location header to the final URL and the status your framework documents: 308 or 307 for Next.js.

  2. 2

    Look for chains

    Run curl -sIL https://www.example.com/old-path. Anything beyond one hop before a 200 should be collapsed in Studio.

  3. 3

    Test in preview

    Sanity's guide recommends an environment where redirects can be checked before going live; use a preview deployment, then publish.

  4. 4

    Watch Search Console

    Sanity's guide recommends Search Console or a similar tool to see where indexing issues show up after a move.

Questions

Asked a lot.

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

01Does Sanity have a built-in redirect feature?

Sanity's own guide treats redirects as content you model yourself and a framework you wire up, because each framework handles them differently.

02Why does my Sanity redirect return 308, not 301?

Next.js documents permanent: true as 308 and permanent: false as 307. Google treats 301 and 308 as permanent redirects, so it is the expected result.

Sources · 6

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • sanity.io
  • nextjs.org
  • vercel.com
  • google.com
  1. 01Implementing redirects | Sanity Learnsanity.io · checked 2026-11-01
  2. 02Managing redirects with Sanity | Sanity Docssanity.io · checked 2026-11-01
  3. 03redirects | Next.js docsnextjs.org · checked 2026-11-01
  4. 04Redirects | Vercel Docsvercel.com · checked 2026-11-01
  5. 05Redirects and Google Search | Google Search Centraldevelopers.google.com · checked 2026-11-01
  6. 06Site moves with URL changes | Google Search Centraldevelopers.google.com · checked 2026-11-01
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