Rewrite to index.html ignored for React + Vite SPA (404 on routes)

Hi Marissa, you’re right this was a baffling one!

The issue was that cleanUrls: true removes the .html from paths, so your destination rewrite needs to also remove it. I’ll reach out internally and see if we can get this documented

Either of these should work

With cleanUrls removed

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/index.html"
    }
  ],
  "regions": [
    "iad1"
  ],
  "trailingSlash": false,
  "git": {
    "deploymentEnabled": {
      "main": true
    }
  }
}

With cleanUrls enabled

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/index"
    }
  ],
  "regions": [
    "iad1"
  ],
  "cleanUrls": true,
  "trailingSlash": false,
  "git": {
    "deploymentEnabled": {
      "main": true
    }
  }
}
1 Like