# 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.

Canonical: https://scaplet.com/seo/sanity/redirects

Guide Sanity 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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fsanity%2Fredirects%20(%22Sanity%20redirects%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fsanity%2Fredirects%20(%22Sanity%20redirects%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fsanity%2Fredirects%20(%22Sanity%20redirects%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fsanity%2Fredirects%20(%22Sanity%20redirects%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 4 parts, 3 minutes.

1. [Two documented schemas, one decision 01](#two-documented-schemas-one-decision)
2. [Schema, query and Next.js config 02](#schema-query-and-next-js-config)
3. [Surprises worth knowing 03](#surprises-worth-knowing)
4. [Check it worked 04](#check-it-worked)

_01_Pick the field type

## Two documented schemas, one decision

Sanity documents two ways to model the same [thing](/glossary/entity). Sanity Learn's SEO course uses plain `string` fields. The developer guide "Managing redirects with Sanity" uses `slug` fields and says it is hard to nail down one approach because frameworks handle redirects differently. Both produce a `redirect` document that matches what the framework expects.

### Reads in GROQ

`string` fields (Learn course)

`source, destination, permanent`

`slug` fields (developer guide)

`"source":source.current`, `"destination":destination.current`, `permanent`

### External destinations

`string` fields (Learn course)

Yes: validation accepts a valid URL or an internal path

`slug` fields (developer guide)

No: the guide's validator requires a leading `/`

### Enable switch

`string` fields (Learn course)

`isEnabled` boolean, filtered in the query

`slug` fields (developer guide)

Not in the guide's schema

### Best for

`string` fields (Learn course)

Rules that sometimes leave your site

`slug` fields (developer guide)

Internal path moves only

Use `string` if any rule may point off-site, and keep the `isEnabled` toggle so an editor can pause a rule without deleting it.

_02_Fix it on your stack

## Schema, query and Next.js config

Validation from Sanity's course (trimmed)
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
Query

```
*[_type == "redirect" && isEnabled == true] { source, destination, permanent }
```

next.config.ts
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.

_03_Worth 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](/glossary/internal-links) rather than lean on the redirect.

_04_How 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](/glossary/google-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.

_01_ Does 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.

_02_ Why 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. 01 [Implementing redirects | Sanity Learn](https://www.sanity.io/learn/course/seo-optimization/implementing-redirects) sanity.io · checked 2026-11-01
2. 02 [Managing redirects with Sanity | Sanity Docs](https://www.sanity.io/docs/developer-guides/managing-redirects-with-sanity) sanity.io · checked 2026-11-01
3. 03 [redirects | Next.js docs](https://nextjs.org/docs/app/api-reference/config/next-config-js/redirects) nextjs.org · checked 2026-11-01
4. 04 [Redirects | Vercel Docs](https://vercel.com/docs/redirects) vercel.com · checked 2026-11-01
5. 05 [Redirects and Google Search | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/301-redirects) developers.google.com · checked 2026-11-01
6. 06 [Site moves with URL changes | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes) developers.google.com · checked 2026-11-01

## Keep learning

[All platform guides](/seo)

[Learn Sanity XML sitemap Headless CMS](/seo/sanity/xml-sitemap) [Related Redirect chains Redirects](/seo-issues/redirect-chains) [Read next Sanity SEO Headless CMS](/seo/sanity) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[Sanity SEO](/seo/sanity)

More in Sanity SEO
[Sanity image SEO](/seo/sanity/image-seo) [Sanity redirects](/seo/sanity/redirects) [Sanity structured data](/seo/sanity/structured-data) [Sanity XML sitemap](/seo/sanity/xml-sitemap)

Terms on this page
[Entity](/glossary/entity) [Internal links](/glossary/internal-links) [Google Search Console](/glossary/google-search-console)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
