Sanity Studio 404 error on /desk route when hosting on Netlify
This is a common issue when deploying Sanity Studio to Netlify! The problem is that Sanity Studio is a single-page application (SPA), and when you navigate to routes like /desk, Netlify tries to find an actual file at that path instead of serving your index.html file.
The solution is to add a _redirects file to tell Netlify to serve your index.html for all routes. Here's how to fix it:
The Solution
Create a file called _redirects (no file extension) in your Studio's public folder with this content:
/* /index.html 200
This tells Netlify to serve your index.html file for all routes (the /* wildcard) with a 200 status code, which allows the Studio's client-side routing to handle the navigation properly.
Where to Place the File
The location depends on your setup:
- Standard Studio setup: Create
public/_redirectsin your Studio directory - Monorepo setup: Create it in
studio/public/_redirects(or wherever your Studio lives)
The public folder's contents get copied to the build output when you run sanity build, so the _redirects file will end up in your dist folder where Netlify can read it.
Netlify Build Settings
Make sure your Netlify configuration is correct:
- Build command:
sanity build(ornpm run buildif you've set up a build script) - Publish directory:
dist(orstudio/distfor monorepos)
Why This Happens
Single-page applications like Sanity Studio use client-side routing, meaning routes like /desk don't correspond to actual files on the server. Without the redirect rule, Netlify looks for a file called desk and returns a 404 when it doesn't find one. The _redirects file tells Netlify to always serve the index.html, which then loads the Studio JavaScript that handles the routing.
After deploying with this change, navigating directly to /desk or any other Studio route should work correctly in all browsers!
Show original thread3 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.