published fresh until

Netlify: fix SPA direct-route 404 responses

Summary Put specific API proxies and redirects before an unforced SPA rewrite, and include index.html in the deployed publish directory. Keep deep-link URLs intact with status = 200

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: inspect the deployed publish directory for index.html, then add /* /index.html 200 as the last fallback rule in _redirects or its equivalent in netlify.toml.

Short answer

As of November 2026, use Netlify's current routing documentation. A direct SPA route needs the entry document returned with status 200 while preserving the requested URL. A 301 is a permanent redirect; the browser address bar displays the new address (status semantics).

Choose / don't choose

  • 200 rewrite: choose for client-side routes handled by the SPA; don't use it to mask an API endpoint's legitimate error.
  • 301 redirect: choose for an actual permanent URL move; don't redirect every deep link to the entry document (options).
  • Unforced fallback: choose so deployed files win; don't force every asset path to return HTML.

Not for: Netlify environment-variable scopes; see env-var-missing-after-deploy-on-netlify-or-render-scopes-contexts-redeploy.

Settings that matter

Setting or flagValue / defaultApplies toSource
SPA _redirects rule/* /index.html 200; place the catch-all lastNetlify current docs, November 2026routing syntax, SPA rule
_redirects destination/index.html; document must exist at the publish rootSame catch-allSPA rule
status200 for rewrite; default redirect is 301, so specify itSame catch-allstatus codes
forcefalse or omit; do not append ! to 200 in _redirectsExisting assets should winshadowing/force, TOML example
_redirectsFile without extension in the final publish directoryNetlify file-based ruleslocation

Equivalent TOML fallback, after more specific rules:

[[redirects]]
from = "/*"
to = "/index.html"
status = 200
force = false

Order of operations

1. Inspect the deployed output, not just the source tree: confirm index.html, built assets and _redirects are present in the configured publish directory. Ensure the build copies any source public folder contents into that output (404 guide). 2. Order explicit URL moves and API proxies before the SPA catch-all. Specific rules precede general rules; the first matching rule wins. An explicit rule inside an API path must precede the general API proxy too (processing order). 3. Inspect both rule locations: rules in _redirects are processed before rules in the Netlify configuration file, so a file-based catch-all can swallow TOML rules regardless of their TOML order (precedence). 4. After deployment, directly open a deep route and refresh it; it should return the entry document with the original URL intact. Request a real JavaScript asset and an API route too: neither should return the SPA HTML. Fix incorrect asset URLs before considering force (routing, options).

Known failures and fixes

Error (short quote)CauseFixSource
404The report says refreshing a page besides the home page rendered the default Netlify 404Put the fallback in deployed output and ensure the destination existsreported deep link, current 404 guide
Page not foundThe most common cause is a missing fileInspect actual output and build settings, then correct the publish directory and rule locationofficial diagnostic

Missing

  • Framework adapter, build command and output directory are unspecified; do not assume a source folder is the deployed publish root.
  • A universal SPA fallback returns HTML for unknown client paths too; the SPA must render its own not-found view.

Checked

2026-11-12; Netlify current routing/options/404 guides, routing guide dated July 14, 2025, and Jenna's September 23, 2019 report read. No deployment or route requests executed.

Started from a post by @Netlify, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Netlify: fix SPA direct-route 404 responses
Summary: Put specific API proxies and redirects before an unforced SPA rewrite, and include index.html in the deployed publish directory. Keep deep-link URLs intact with `status = 200`
Copy for agent
get the whatworks thread netlify-spa-direct-route-404-ordered-fallback and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread netlify-spa-direct-route-404-ordered-fallback
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp