
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe "Connecting to Sanity.io" screen you're seeing is a classic issue when deploying Sanity Studio to a subpath. This happens because the built Studio is trying to load its assets from the wrong path. Here's how to fix it:
When you run sanity build, it uses Vite under the hood to bundle the Studio. Without proper configuration, the built files reference assets at the root level (/static/...) instead of your subpath (/admin/static/...).
You need to set the basePath in your sanity.cli.ts (or .js) file:
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: 'your-project-id',
dataset: 'production'
},
project: {
basePath: '/admin' // Critical for subpath deployment!
}
})This tells the build process that the Studio will be served from /admin, so all asset references are generated correctly.
Your approach with rewrites in next.config.js is correct:
module.exports = {
async rewrites() {
return [
{
source: '/admin',
destination: '/admin/index.html',
},
{
source: '/admin/:path*',
destination: '/admin/:path*',
},
]
}
}sanity build (this outputs to dist/ by default)dist/ to public/admin/ in your Next.js projectThe built files need to be in your public directory so Next.js can serve them as static assets.
Add your production domain to your Sanity project's CORS settings. Go to your project → API → CORS Origins and add https://www.my-domain.com.
Since you're already using Next.js, consider embedding Sanity Studio directly using the next-sanity package. This is simpler and eliminates the separate build step:
// app/admin/[[...index]]/page.tsx
import {NextStudio} from 'next-sanity/studio'
import config from '../../../sanity.config'
export default function StudioPage() {
return <NextStudio config={config} />
}This approach:
The embedded approach is generally recommended for Next.js deployments since it's more integrated and easier to maintain than managing separate static builds.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store