Your site works. You click through to /about, it renders, everything is fine. Then you press refresh — or send somebody the link — and the host answers 404.
Nothing is broken. The URL was never real. A client-side router invents paths inside a page that is already open: it changes the address bar and swaps what React or Vue renders, without asking the server for anything. Refreshing skips all of that. The browser goes to the host and asks for a file at /about, the host looks, there is no about.html and no about/index.html, and it answers the only honest thing it can.
The fix is one rule, and it is the same rule everywhere: when a path has no file, serve index.html with status 200. The app boots, reads the address, and renders the page it would have rendered anyway. What differs between hosts is only where you write that rule down.
The 30-second version
| Host | What to do |
|---|---|
| Netlify | _redirects file with /* /index.html 200 |
| Cloudflare Pages | the same _redirects, in the output folder, fallback rule last |
| Vercel | vercel.json with a rewrite from /(.*) to /index.html |
| GitHub Pages | no rewrites exist — copy index.html to 404.html (read the caveat below) |
| nginx | try_files $uri $uri/ /index.html; |
| Apache | mod_rewrite, falling back to /index.html |
| Drop2Run | a setting on the site: Single-page app |
What is actually happening
Two routers think they own the same URL space, and only one of them is awake.
When you navigate inside the app, the browser's own router runs: it pushes a history entry, the address bar changes, the framework renders a different component. No request leaves the machine. This is why the bug is invisible in development — a dev server is built to serve the app shell for everything, so the failing case never happens while you are working.
When you refresh, there is no app yet. The browser makes an ordinary HTTP request for the path in the address bar, and a static host answers requests by looking for a file. / finds index.html. /about finds nothing. The app that knows what /about means is inside index.html, which is the file the host just decided not to send.
So the rule is not a trick or a workaround. It is you telling the host the truth: this site has one document, and it is responsible for every path.
The fix, host by host
Netlify
A file named _redirects, no extension, in the directory you publish:
/* /index.html 200Put more specific rules above it. Rules are read top to bottom and the first match wins, so a catch-all placed first swallows everything below it.
Cloudflare Pages
The same file and the same line. Two things go wrong here more often than on Netlify:
- The file must be in the build output, not in your source tree. With Vite, Astro or SvelteKit, put it in
public/(orstatic/) so the build copies it across untouched. A_redirectssitting next topackage.jsondoes nothing at all. - The fallback goes last. Same first-match rule as above.
Vercel
vercel.json at the root of the project:
{
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}A rewrite, not a redirect: the URL the visitor sees stays /about, and the content served is the shell. A redirect would send them to / and lose the path, which is the bug wearing a different hat.
GitHub Pages
There is no rewrite mechanism, and this is the one host where the usual advice has a cost. The workaround is to copy your built index.html to 404.html and publish both. GitHub serves 404.html for any path it cannot find, your app boots inside it, and the page renders.
It works. What it does not do is change the status code: that response is still a 404, because as far as the server is concerned nothing was found. Your visitor sees the right page. A crawler sees a page that reports it does not exist, and will generally decline to index it. If those URLs need to be found in a search engine, this workaround is not enough on its own — a host that can answer 200 is.
nginx
location / {
try_files $uri $uri/ /index.html;
}Apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>The two RewriteCond lines are the whole safety of it: rewrite only when the request is not an existing file and not an existing directory. Without them your images and stylesheets become copies of the HTML.
Drop2Run
A setting on the site rather than a file in the folder: choose Single-page app in the site's settings and an unknown path serves index.html with a 200. Nothing to add to the build, and it can be turned on after the folder is already published. What publishing a build looks like here.
The status code is the part people get wrong
Three different responses look identical in a browser and mean three different things to everything else:
- 200 with the shell. What you want. The page exists, here it is.
- 404 with the shell — the GitHub Pages workaround. The visitor is fine; crawlers and uptime checks are told the page is missing.
- 302 to
/. The path is thrown away before the app can read it, so every deep link lands on the home page. This is the one that looks like it works right up until somebody shares a link.
If you only check the fix by clicking around, all three pass. Check it the other way:
curl -I https://your-site.example/some/deep/pathYou want HTTP/2 200 and a content-type of text/html.
When you should not do this
A fallback rule is a promise that every path is real, and if that is not true of your site it does damage quietly:
- Your site is several HTML files, not an app.
/about.htmlalready works. Turning on a fallback means a typo like/abuot.htmlserves your home page with a 200 instead of a 404 — and a search engine may file that as a duplicate of your front page rather than as a mistake. - You want a real 404 page. With the fallback on, nothing is ever missing, so your 404 page is unreachable by definition. If your router has a not-found screen, that is now where wrong paths land, and you should make sure it says so rather than rendering an empty layout.
- You serve files that are not part of the app — a PDF, a
sitemap.xml, a webhook target. Make sure the real file is checked first (try_filesand the Apache conditions above do this; a blanket rewrite does not).
Troubleshooting
Deep links work, assets 404. The fallback is matching your JavaScript and CSS too, so the browser gets HTML where it expected a script. Check that the rule runs only after a file lookup fails.
It works locally, fails when deployed. The config file is not in what you published. Confirm the built output actually contains _redirects or vercel.json — not just the repository.
The URL changes to / on refresh. You wrote a redirect where a rewrite was needed. Fix the status code, not the path.
Refresh loops or warns about a loop. A catch-all pointing at a path the same catch-all also matches. Either put specific rules first or use a distinct fallback file.
Everything works but search results are missing. Check the status code with curl -I. This is the GitHub Pages case above, and it does not announce itself.
Questions
Is this a bug in my framework? No. It is what client-side routing is: the framework owns URLs the server has never been told about. Every SPA on every static host needs this rule, which is why every host has a way to express it.
Does this hurt SEO? The rule itself does not — a 200 with real content is exactly what a crawler wants. Two things around it can: serving the shell with a 404 status, and serving an empty shell that only fills in after JavaScript runs. If the content matters for search, pre-render the pages or use a framework that emits real HTML per route.
Should I use hash routing instead?
It avoids the problem — /#/about is one URL as far as the server is concerned — at the cost of URLs people find ugly and of some tooling that treats the fragment as noise. If you can set the rule, set the rule.
How do I keep a real 404 page?
Handle it in the app: render a not-found screen for unmatched routes. On a host that serves a 404.html when there is no fallback, you can also keep both — the fallback for the routes your app knows, and a real 404 for everything else, if the host lets you enumerate them. Where that 404.html goes on each host is in how to add a custom 404 page.