Reads in GROQ
- `string` fields (Learn course)
source, destination, permanent- `slug` fields (developer guide)
"source":source.current,"destination":destination.current,permanent
Model redirects as Sanity documents with validation, feed them to Next.js or Astro, and avoid the 301 versus 308 and redeploy surprises.
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.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
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.source, destination, permanent"source":source.current, "destination":destination.current, permanent/isEnabled boolean, filtered in the queryUse string if any rule may point off-site, and keep the isEnabled toggle so an editor can pause a rule without deleting it.
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 })*[_type == "redirect" && isEnabled == true] {
source,
destination,
permanent
}import { fetchRedirects } from '@/sanity/lib/fetchRedirects'
const nextConfig: NextConfig = {
async redirects() {
return await fetchRedirects()
},
}
export default nextConfigThe 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.
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.
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.
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."
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.
The guide says to update old internal links rather than lean on the redirect.
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.
Run curl -sIL https://www.example.com/old-path. Anything beyond one hop before a 200 should be collapsed in Studio.
Sanity's guide recommends an environment where redirects can be checked before going live; use a preview deployment, then publish.
Sanity's guide recommends Search Console or a similar tool to see where indexing issues show up after a move.
2 questions people ask next, answered from the sources on this page.
Sanity's own guide treats redirects as content you model yourself and a framework you wire up, because each framework handles them differently.
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.
Run the free audit, then approve the fixes. Every change can be undone.