Studio Hard Refresh Causing a 404 Response Hosted on Netlify

4 replies
Last updated: Dec 31, 2021
Howdy, having issues with Studio hard refresh causing a 404 response hosted on Netlify. I’ve tried the suggested solutions via
_redirect
and
netlify.toml
Nothing seems to make a difference. Frontend using NextJS. Thanks in advance for any suggestions.
netlify.toml
[[redirects]]
  from = "/*"
  to = "/"
  status = 200

_redirect in root
 /studio/* /studio 200
AI Update

This is a classic routing issue when embedding Sanity Studio in a Next.js app on Netlify. The problem is that Netlify needs to know how to handle the Studio's client-side routing, especially for routes like /studio/desk.

The issue you're experiencing is that your current _redirects and netlify.toml configurations aren't quite right for an embedded Studio setup. Based on a similar issue that was resolved, here's what you need to do:

If you're using the catch-all route pattern (like app/studio/[[...index]]/page.tsx or pages/studio/[[...index]].tsx), you need to ensure Netlify redirects all /studio/* paths to the Studio's index file.

Try updating your netlify.toml to:

[[redirects]]
  from = "/studio/*"
  to = "/studio"
  status = 200

Or if you prefer using _redirects file in your Next.js project root:

/studio/*  /studio  200

The key difference from what you have is that you need to redirect /studio/* specifically to /studio (not to /), and you should remove the generic catch-all redirect that's routing everything to /index.html.

If you have a vercel.json file in your project (even though you're deploying to Netlify), it might be interfering. Make sure it's not there, or if you need it for Vercel previews, ensure it has the correct configuration:

{
  "rewrites": [
    { "source": "/studio/(.*)", "destination": "/studio/index.html" }
  ]
}

The problem occurs because when you hard refresh at /studio/desk, Netlify tries to find that exact file path on the server, which doesn't exist. The redirect tells Netlify to serve the Studio's index file for all Studio routes, allowing the client-side routing to take over and handle the /desk route properly.

After making these changes, redeploy your site to Netlify and the 404 errors on refresh should be resolved!

Did you install gatsby-plugin-netlify ?
Hi Kevin. Does the URL change when you refresh?
no gatsby-plugin-netlify installed. Using Netlify and NextJS, and from what I understood those plugins aren’t necessary anymore, unless I’m mistaken?
Refresh doesn’t not change the URL, however opening Studio at
/studio
it routes/loads
/studio/desk
as the base URL
I sorted it out, thanks all for the help. Issue was another eng set the base path which I wasn’t aware of to include
studio
I mistaken assumed that was part of Sanity “Studio”

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.

Was this answer helpful?