Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to Fix the Vercel Rewrite Rules for Sanity

4 replies
Last updated: May 5, 2021
Hi, how do you fix the Vercel rewrite rules for Sanity? I lifted this line from their blog, but it doesn’t actually work:
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
May 4, 2021, 12:03 PM
this works for me in vercel.json

{
  "routes": [
    { "handle": "filesystem" },
    { "src": "/(.*)", "dest": "/index.html" }
  ]
}
or when hosting the sanity spa inside a next project I use this in next.config.js


async rewrites() {
  return [
    { source: "/cms", destination: "/cms/index.html" },
    { source: "/cms/:path*", destination: "/cms/index.html" },
  ];
},
May 4, 2021, 12:07 PM
Thanks, for some reason I can’t seem to get
routes
to work either. I’m thinking maybe I’ll try wrapping it in a next app if the next few deploys don’t take.
May 4, 2021, 4:27 PM
Some thoughts: Is the sanity index.html there at all (the file is created with
sanity build
and in the right directory)? No conflicting routes (now.json / vercel.json, next.config)? Have you tried using the vercel cli locally?
May 5, 2021, 5:33 AM
Those are good ideas. After I came back with fresh eyes, I realized
"cleanUrls": true
was the culprit. Though I’m really not sure how that could get in the way of
/desk
. Anyway, thanks again for the help! 🙂
May 5, 2021, 9:38 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?