# Check SPA HTTP status codes

- Check 08.13 · JavaScript and HTML rendering · Critical
- Source: https://checklist-seo-geo.com/en/javascript-html-rendering/check-spa-http-status-codes
- Make your single-page application return real 404, 301 and 5xx codes instead of 200 everywhere, on Apache, Nginx, Cloudflare, AWS, Netlify, Vercel or Next.js.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/javascript-html-rendering/check-spa-http-status-codes.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

A single-page application (SPA) often serves the same `index.html` for every URL, with a `200` code, then lets JavaScript decide what to display. The result: a page that does not exist, an old address and an API error all answer “success”. This check consists of testing the HTTP codes returned for each type of URL, then having the server, the CDN or the framework send the right codes: `404` for what does not exist, `301` for what has moved, `5xx` for outages, `200` for everything else.

## Why it matters

The HTTP code is the first piece of information a crawler receives, before any rendering. Google says so in its JavaScript documentation: use a meaningful status code, such as a `404` for a page that cannot be found. It also specifies that rendering may be skipped for a response other than `200`.

With a universal `200`:

- **Google** has to render every URL, read “Page not found” and infer a soft 404. Real errors get mixed up with real pages in the reports, and made-up URLs (broken links, parameters) use up crawling.
- **Crawlers that do not execute JavaScript**, which include most AI crawlers according to the analysis Vercel published in December 2024, receive the same empty shell with a `200` for every URL: they can tell neither a real page from a missing one, nor a page that has moved.
- **Redirects done in JavaScript** are only seen after rendering. Google follows them, but recommends server-side redirects when they are possible.

## What it improves

- **Indexing reports**: fewer soft 404s, and errors classified under their real name.
- **Crawling**: nonexistent URLs respond with `404` and are crawled less and less.
- **Signal transfer**: old URLs redirected with a server-side `301` pass their signals on to the new address.
- **Crawlers without JavaScript**: a reliable code for each URL, without depending on rendering.
- **Monitoring**: uptime tools finally see outages, instead of a `200` that hides an error page.

## How to check

Test one URL from each category:

```bash
while read -r url; do
  curl -s -o /dev/null -w "%{http_code} %{redirect_url} $url\n" "$url"
done <<'EOF'
https://example.com/
https://example.com/produits/theiere-fonte
https://example.com/produits/produit-inexistant-8431
https://example.com/n-importe-quoi-8431
https://example.com/ancienne-boutique/theieres
https://example.com/compte
EOF
```

Compliant result:

| URL | Expected code | Typical code from a misconfigured SPA |
|---|---|---|
| Home page, existing item page | `200` | `200` |
| Nonexistent resource on a valid route | `404` or `410` | `200` |
| Unknown path | `404` | `200` |
| Old URL that has moved | `301` or `308` to the new one | `200` then a JavaScript redirect |
| Logged-in area | `200` login page with `noindex`, `302` to the login page, or `401`/`403` | `200` |
| API down during server rendering | `503` or `500` | `200` with an error message |

Complete this with Search Console: the “Soft 404” row of the [Page indexing report](https://search.google.com/search-console/index) lists the URLs concerned, and [URL Inspection](https://search.google.com/search-console?action=inspect) shows the code and the rendered page.

> **Good to know:** the browser's developer tools often show `200` for an in-app navigation in an SPA, because no page request is made. Always test the URL loaded directly, with curl or in a new tab.

## How to implement

### Before you start

Three strategies, from most to least robust:

1. **Server rendering or prerendering**: the framework knows about the resource when it responds and sets the code. This is the complete solution; see [prefer SSR/SSG for critical content](https://checklist-seo-geo.com/en/javascript-html-rendering/prefer-ssr-ssg-critical-content-if-relevant).
2. **List of routes on the server side**: the server or the CDN only serves `index.html` for real route patterns (`/`, `/blog/…`, `/produits/…`) and returns `404` for everything else. Unknown paths are handled; a nonexistent resource on a valid route (`/produits/produit-inexistant`) still requires step 3.
3. **Client-side fixes**, documented by Google: redirect in JavaScript to a URL the server serves with a `404`, or add a `noindex` tag to the error view.

Permanent redirects, for their part, are always declared on the server or the CDN, never only in the JavaScript router.

### Apache

Versions: Apache 2.4 (mod_rewrite module).

Replace the catch-all fallback (`FallbackResource /index.html`, or a rule that sends everything to `index.html`) with a list of routes, in the virtual host or the `.htaccess` file:

```apache
RewriteEngine On

RewriteRule ^ancienne-boutique/(.*)$ /produits/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(blog|blog/[a-z0-9-]+|produits/[a-z0-9-]+|contact)/?$ /index.html [L]

ErrorDocument 404 /404.html
```

`404.html` is a static file, which can load the application to display a polished error page: all that matters is the `404` code sent by Apache.

### Nginx

Versions: Nginx 1.18 and later, including the 1.30 stable branch.

```nginx
server {
    root /var/www/example/dist;
    index index.html;
    error_page 404 /404.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ ^/(blog|blog/[a-z0-9-]+|produits/[a-z0-9-]+|contact)/?$ {
        try_files /index.html =404;
    }

    location ^~ /ancienne-boutique/ {
        rewrite ^/ancienne-boutique/(.*)$ /produits/$1 permanent;
    }
}
```

The common configuration `try_files $uri $uri/ /index.html;` in `location /` is the one that returns `200` everywhere. Reload with `sudo nginx -t && sudo systemctl reload nginx`.

### Cloudflare

Versions: Cloudflare Workers with static assets and Cloudflare Pages, all plans, November 2026.

- **Workers with static assets**: `not_found_handling = "single-page-application"` serves `index.html` with a `200` for any unknown URL. With `"404-page"`, Workers serves the nearest `404.html` with a `404` code; then add the application's routes in the Worker's code.
- **Cloudflare Pages**: without a `404.html` at the root, Pages treats the project as an SPA and serves the root for any unknown path. Add a `404.html` and declare the application's routes in `_redirects` with the `200` code.
- **Redirects**: declare 301s in `_redirects` or in [Redirect Rules](https://dash.cloudflare.com/?to=/:account/:zone/rules/overview).

Purge the cache after the change.

### AWS

Versions: Amazon CloudFront (CloudFront Functions) and AWS Amplify Hosting, AWS console, November 2026.

The classic S3 + CloudFront setup maps, in the distribution's `Error pages` tab, 403 and 404 errors to `/index.html` with a `200` code: this is the source of the universal `200`. Replace it with a CloudFront Function, associated with the viewer request event, that only rewrites real routes:

```js
function handler(event) {
    var request = event.request;
    var appRoutes = /^\/(blog(\/[a-z0-9-]+)?|produits\/[a-z0-9-]+|contact)\/?$/;

    if (appRoutes.test(request.uri)) {
        request.uri = '/index.html';
    }

    return request;
}
```

Keep a custom error response that maps 403 and 404 to `/404.html` with a `404` code. 301 redirects can also live in this function. On **Amplify Hosting**, the rewrite rule to `/index.html` with a `200` suggested for SPAs has the same effect: limit it to real route patterns.

### Netlify

Versions: Netlify `_redirects` file, all plans, November 2026.

The `/* /index.html 200` rule returns `200` for every path. List the routes, add the redirects, and finish with a `404` rule:

```txt
/ancienne-boutique/*   /produits/:splat   301
/blog                  /index.html        200
/blog/*                /index.html        200
/produits/*            /index.html        200
/contact               /index.html        200
/*                     /404.html          404
```

### Vercel

Versions: Vercel `vercel.json` file, all plans, November 2026.

Do not use a global rewrite to `/index.html`. In `vercel.json`, rewrite only the application's routes; everything else receives `404.html` with a `404` code:

```json
{
  "redirects": [
    { "source": "/ancienne-boutique/:path*", "destination": "/produits/:path*", "permanent": true }
  ],
  "rewrites": [
    { "source": "/blog/:slug*", "destination": "/index.html" },
    { "source": "/produits/:slug", "destination": "/index.html" },
    { "source": "/contact", "destination": "/index.html" }
  ]
}
```

`"permanent": true` produces a `308` code, which Google treats like a `301`.

### Next.js

Versions: Next.js 15 and 16 (App Router and Pages Router).

Next.js sets the codes on the server side. In both routers, permanent redirects are declared in `redirects()` in `next.config.ts` (or `next.config.js`) with `permanent: true`, which produces a `308`. The rest depends on the router.

#### App Router

- **Not found**: `notFound()` in the page or the data function. It returns a `404` if it runs before the response starts; called after streaming has started, under a `<Suspense>`, the response keeps its `200` and Next.js adds a `noindex` tag. Check that the resource exists before any streaming.
- **Redirects**: `permanentRedirect()` in a page (`308`). `redirect()` returns a `307`, which is temporary.
- **Errors**: an exception thrown during rendering, before streaming, produces a `500`; `error.js` only changes how it is displayed.

#### Pages Router

- **Not found**: `return { notFound: true }` in `getStaticProps` or `getServerSideProps` returns a `404` with the `pages/404.tsx` page.
- **Redirects**: `return { redirect: { destination: '/produits', permanent: true } }` in the same functions produces a `308`; `permanent: false` gives a `307`.
- **Errors**: an exception thrown in `getServerSideProps` produces a `500` with the `pages/500.tsx` page.
- **Trap**: a page that only loads its data in the browser returns `200` even for a nonexistent resource.

### Nuxt

Versions: Nuxt 3 and 4.

```js
// pages/produits/[slug].vue, in <script setup>
const route = useRoute();
const { data: product } = await useFetch(`/api/products/${route.params.slug}`);

if (!product.value) {
  throw createError({ status: 404, statusText: 'Product not found' });
}
```

With server rendering, Nuxt returns the `404` with the `error.vue` page. For redirects, use `routeRules` in `nuxt.config.ts` (`'/ancienne-boutique': { redirect: { to: '/produits', statusCode: 301 } }`) or `navigateTo(url, { redirectCode: 301 })`. Older versions of Nuxt use `statusCode` and `statusMessage` in `createError`.

### Angular with server rendering

With Angular's server-side rendering, the server route configuration accepts a `status` property, useful for the catch-all route:

```ts
// app.routes.server.ts
import { RenderMode, ServerRoute } from '@angular/ssr';

export const serverRoutes: ServerRoute[] = [
  { path: '**', renderMode: RenderMode.Server, status: 404 },
];
```

For a resource that cannot be found on a valid route, inject `RESPONSE_INIT` from `@angular/core` into the error component and set `status` to `404`. This token is `null` in the browser and during prerendering: check that it is present before using it.

### Astro

Versions: Astro 5 to 7.

With server rendering, return `return new Response(null, { status: 404 })` in the page's frontmatter, and `return Astro.redirect('/produits/theiere-fonte', 301)` for a redirect. In static mode, `src/pages/404.astro` produces the `404.html` served by the host.

### Single-page applications without server rendering

For a nonexistent resource, Google suggests two fixes. The first redirects to a URL the server serves with a `404`:

```js
const response = await fetch(`/api/products/${slug}`);

if (response.status === 404) {
  window.location.replace('/404');
}
```

The second adds a `noindex` tag to the error view:

```js
const meta = document.createElement('meta');
meta.name = 'robots';
meta.content = 'noindex';
document.head.appendChild(meta);
```

The first is preferable: the `404` code can be read by every crawler once the redirect is followed. For a temporary API outage, do not add `noindex`: display a message with a button to try again, otherwise an outage of a few minutes could remove real pages from the index. Finally, fix the causes at the source: see [check content loaded via API](https://checklist-seo-geo.com/en/javascript-html-rendering/check-content-loaded-via-api).

## Common mistakes

- **Testing an in-app navigation in the browser**: no page request is made, so the `200` displayed means nothing.
- **Redirecting unknown URLs to the home page**: Google may treat these redirects as soft 404s.
- **Redirects declared only in the JavaScript router**: invisible to crawlers that do not render, and seen late by Google.
- **`noindex` added on a temporary API error**: real pages drop out of the index.
- **Route list forgotten when a section is added**: the new section responds with `404`. Include it in acceptance testing.
- **`/404` itself served with a `200`**: the JavaScript redirect is then useless.

## Frequently asked questions

### Why does my single-page application return 200 for every URL?

A single-page application returns 200 for every URL because the server or the CDN is configured to serve index.html for every unknown path: try_files to index.html on Nginx, FallbackResource on Apache, a /* /index.html 200 rule on Netlify, a CloudFront error page rewritten to 200. The server does not know which routes exist. Limit this rule to real route patterns and return 404 for everything else.

### Is a JavaScript redirect as good as a 301 redirect?

No, a JavaScript redirect is not quite as good as a 301 redirect. Google follows it, but only after rendering the page, and recommends server-side redirects whenever possible. Crawlers that do not execute JavaScript do not see it at all and stay on the old URL. So declare permanent redirects in the server, the CDN or the framework, and keep JavaScript redirects for cases where there is no other option.

### Is a redirect to /404 better than a noindex tag?

For a nonexistent resource in a single-page application, a JavaScript redirect to a URL served with a real 404 code is preferable: the status code can be read by every crawler once the redirect is followed. A noindex tag added by JavaScript is only seen after rendering, so mostly by Google. Both solutions are documented by Google; server rendering, which sets the code in the response itself, remains the best.

### How can Next.js return 200 for a page that is not found?

Next.js returns 200 for a page that is not found when notFound() is called after streaming has started, for example in a component placed under a Suspense boundary: the headers have already been sent. Next.js then adds a noindex tag, but the code stays 200. To get a real 404, check that the resource exists in the page itself, before any content is streamed.

## Resources

- [Google Search Central: Understand the JavaScript SEO basics](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics?hl=en)
- [Google Search Central: Redirects and Google Search](https://developers.google.com/search/docs/crawling-indexing/301-redirects?hl=en)
- [Google Search Central: How HTTP status codes affect Google Search](https://developers.google.com/search/docs/crawling-indexing/http-network-errors?hl=en)
- [Next.js: notFound](https://nextjs.org/docs/app/api-reference/functions/not-found)
- [Cloudflare Workers: Single Page Application (SPA)](https://developers.cloudflare.com/workers/static-assets/routing/single-page-application/)
- [Angular: Server-side rendering](https://angular.dev/guide/ssr)

Next steps: [fix soft 404s](https://checklist-seo-geo.com/en/indexing-canonicalization/fix-soft-404s), [use 301/308 for permanent moves](https://checklist-seo-geo.com/en/http-redirects/use-301-308-permanent-moves) and [avoid information available only in Canvas](https://checklist-seo-geo.com/en/javascript-html-rendering/avoid-information-available-only-canvas).
