# Cloudflare Pages 404 Not Found

> Why a Cloudflare Pages site returns 404 or serves the wrong page: output directory, 404.html lookup, SPA fallback, _redirects and custom domain checks.

Canonical: https://scaplet.com/errors/cdn/cloudflare-pages-404

Guide Cloudflare Pages Error · CDN and hosting

Why a Cloudflare Pages site returns 404 or serves the wrong page: output directory, 404.html lookup, SPA fallback, _redirects and custom domain checks.

5 min

read

7

sources

Oct 31, 2026

updated

Scaplet Editorial Team

author

In one line

A Cloudflare Pages 404 means Pages found no file for the requested path. Check that your build output directory holds the files, that the path matches the file name, and whether a 404.html exists. Without a top-level 404.html, Pages treats the project as a single-page app and serves the root for unknown paths, which hides real 404s from crawlers.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fcdn%2Fcloudflare-pages-404%20(%22Cloudflare%20Pages%20404%20Not%20Found%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fcdn%2Fcloudflare-pages-404%20(%22Cloudflare%20Pages%20404%20Not%20Found%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fcdn%2Fcloudflare-pages-404%20(%22Cloudflare%20Pages%20404%20Not%20Found%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fcdn%2Fcloudflare-pages-404%20(%22Cloudflare%20Pages%20404%20Not%20Found%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

## At a glance

4 facts from the sources below

404.html, closest one up the directory tree

Custom 404 file

Serves / when there is no top-level 404.html

SPA fallback

2,000 static + 100 dynamic = 2,100

_redirects limit

302

Default _redirects code

_01_What Pages does when no file matches

## How Pages decides to return a 404

Cloudflare Pages serves a static file when a file matches the request path. If an HTML file is found with a matching path, Pages serves it, and it redirects HTML pages to their extension-less counterparts: `/contact.html` goes to `/contact`, and `/about/index.html` goes to `/about/`. When no file matches, two documented behaviors decide what the visitor gets.

Your project has

### A `404.html`

Behavior documented by Cloudflare

Pages shows your custom page and looks for the closest `404.html`: first in the same directory as the route, then up the directory tree, ending at `/404.html`

What a crawler sees

Confirm the status line with `curl -I`; Cloudflare's page describes the page that is shown, not the [status code](/glossary/http-status-codes)

Your project has

### No top-level `404.html`

Behavior documented by Cloudflare

Pages assumes a single-page application and serves the root (`/`) for any path that is not a static asset

What a crawler sees

A page that loads normally for a URL that does not exist, which Google can treat as a [soft 404](/glossary/soft-404)

Your project has

### A `_redirects` rule that matches

Behavior documented by Cloudflare

Redirects are always followed, whether or not an asset matches the request

What a crawler sees

The redirect status code, `302` unless you set another

The second row is the surprise. A Pages project without a top-level `404.html` never shows a 404 for a mistyped URL, because the SPA fallback answers instead. If you built a static site (Astro, Hugo, Docusaurus) and want real 404s, add a `404.html` to the build output. Sites served straight from a repository hit the same missing-file problem; see [404s on repository-based static hosting](/errors/cdn/github-pages-404).

_02_How it works

## Find out why a path 404s

Build output directory by framework (Cloudflare presets)
| Framework or tool | Build command | Build output directory |
| Astro | `npm run build` | `dist` |
| React (Vite) | `npm run build` | `dist` |
| Next.js (Static HTML Export) | `npx next build` | `out` |
| Docusaurus | `npm run build` | `build` |
| Hugo | `hugo` | `public` |
| Jekyll | `jekyll build` | `_site` |
| SvelteKit | `npm run build` | `.svelte-kit/cloudflare` |

1. 01

### Request it from the command line

Run `curl -sI https://YOUR-PROJECT.pages.dev/the/path` and read the status line, `Location` and `Cf-Ray` headers. Pages always adds `Cf-Ray` and `Server: cloudflare` to the assets it serves.
2. 02

### Compare pages.dev with your custom domain

Cloudflare's debugging guide says that if errors appear on your custom domain but not on `pages.dev`, set the project's DNS record to DNS Only (grey cloud) and review your zone configuration. Also check Rules > Page Rules for a Cache Everything rule, because Pages handles its own cache.
3. 03

### Open the build log

In the Cloudflare dashboard go to Workers & Pages, select the project, then Deployments > View details > Build log. Pages marks a build successful when the build command exits with 0, even if errors were written to standard error, so an empty or wrong output folder can still deploy.
4. 04

### Check the output directory

Compare your Build output directory with what the build writes. Cloudflare's framework presets list the usual values, in the table below.
5. 05

### Check Functions routes

If you use `/functions`, file paths map to routes (`/functions/fruits/apple.js` serves `/fruits/apple`). When no Function matches, Pages falls back to a static asset if there is one.

_03_Your call

## Add a real 404 page, or fix SPA routes

Pick the setup that matches how the site renders. A static site wants a `404.html`. A client-routed SPA wants the fallback, plus a way to keep non-existent URLs out of Google's index.

If this fits

### Add a top-level 404.html if

- Your site is static or server-rendered output (every URL is a real file).
- You want mistyped and removed URLs to show your own page.
- You are cleaning up soft 404 reports in [Search Console](/glossary/google-search-console).

Or

### Keep the SPA fallback if

- Your app uses client-side routing and needs the root served for deep links such as `/about` or `/help`.
- You handle unknown routes in the app and signal errors to crawlers yourself (see below).
- You accept that unknown paths return the app shell.

Directory layout for a static site with section-level 404 pages

```
dist/ index.html 404.html <- used for any missing path blog/ 404.html <- used for missing paths under /blog/ index.html
```

_redirects: fix moved URLs (one rule per line: source destination code)

```
# the code is optional and defaults to 302 /old-pricing /pricing 301 /blog/* /posts/:splat 301 /docs/* https://docs.example.com/:splat 301
```

**You cannot return a 404 from _redirects**Cloudflare's redirects table marks "Rewrites (other status codes)" as unsupported, with `/blog/* /blog/404.html 404` as the example it lists. Supported codes are 301, 302, 303, 307, 308 for redirects and `200` for proxying. Redirects are also not applied to requests served by Pages Functions.

_04_Check it

## What it does to SEO

Google doesn't use content from URLs that return 4xx, and it removes already indexed URLs that start returning one. A Pages SPA that answers every unknown path with the root page sends a 2xx instead, and Google says that when the content suggests an error, Search Console shows a soft 404. See [soft 404 errors](/seo-issues/soft-404-errors) and [SPA SEO](/glossary/spa-seo).

Google's [JavaScript SEO](/glossary/javascript-seo) guide gives two ways to avoid soft 404s in client-rendered apps: a JavaScript redirect to a URL for which the server responds with a 404 status (for example `/not-found`), or adding a `noindex` [robots meta tag](/glossary/robots-meta-tag) to error pages with JavaScript. On Pages, request your `/not-found` URL with `curl -I` and confirm it returns a 404 status before relying on the redirect approach.

Preview deployments are different: Pages adds `X-Robots-Tag: noindex` when an asset is requested over a preview URL, so a 404 you only see on a preview link is not an indexing issue.

Google's noindex approach for an unknown product

```
fetch(\`/api/products/${productId}\`) .then(response => response.json()) .then(product => { if (product.exists) { showProductDetails(product); } else { // Assumes no other robots meta tag is present const metaRobots = document.createElement('meta'); metaRobots.name = 'robots'; metaRobots.content = 'noindex'; document.head.appendChild(metaRobots); } });
```

Sources · 7

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- cloudflare.com
- google.com

1. 01 [Cloudflare Pages: Serving Pages](https://developers.cloudflare.com/pages/configuration/serving-pages/) developers.cloudflare.com · checked 2026-11-01
2. 02 [Cloudflare Pages: Redirects](https://developers.cloudflare.com/pages/configuration/redirects/) developers.cloudflare.com · checked 2026-11-01
3. 03 [Cloudflare Pages: Debugging Pages](https://developers.cloudflare.com/pages/configuration/debugging-pages/) developers.cloudflare.com · checked 2026-11-01
4. 04 [Cloudflare Pages: Build configuration](https://developers.cloudflare.com/pages/configuration/build-configuration/) developers.cloudflare.com · checked 2026-11-01
5. 05 [Cloudflare Pages: Functions routing](https://developers.cloudflare.com/pages/functions/routing/) developers.cloudflare.com · checked 2026-11-01
6. 06 [Google Search Central: JavaScript SEO basics (soft 404s in single-page apps)](https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics) developers.google.com · checked 2026-11-01
7. 07 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-11-01

Questions

## Asked a lot.

4 questions people ask next, answered from the sources on this page.

_01_ How do I add a custom 404 page on Cloudflare Pages?

Create a `404.html` file in your build output directory. Pages looks for the closest `404.html` to the requested route, going up the directory tree and ending at `/404.html`, so you can also add section-level ones such as `/blog/404.html`.

_02_ Why does every URL on my Pages site load instead of showing a 404?

Without a top-level `404.html`, Cloudflare Pages assumes a single-page application and serves the root (`/`) for any path that is not a static asset. Add a `404.html` if the site is not a client-routed SPA.

_03_ Why does my custom domain 404 but pages.dev works?

Cloudflare's debugging guide says to set the DNS record for the project to DNS Only (grey cloud) and review the zone's configuration. Also remove a Page Rule with Cache Everything, because Pages handles its own cache.

_04_ Can I return a 404 status with a _redirects rule?

No. The redirects documentation marks rewrites with other status codes as unsupported. Only 301, 302, 303, 307 and 308 redirects, and 200 proxying, are supported.

## Keep learning

[All errors](/errors)

[Learn GitHub Pages 404 Not Found CDN and hosting errors](/errors/cdn/github-pages-404) [Related HTTP status codes Crawling and indexing](/glossary/http-status-codes) [Read next 404 Not Found HTTP status codes](/errors/http/404) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 404 errors
[404 Not Found on Apache](/errors/http/404/apache) [404 Not Found on nginx](/errors/http/404/nginx) [AWS Amplify 404 Not Found](/errors/cdn/amplify-404) [CloudFront 404 Not Found](/errors/cdn/cloudfront-404) [Firebase Hosting 404](/errors/cdn/firebase-hosting-404)

More Cloudflare Pages errors
[Cloudflare 504 Gateway Timeout](/errors/cdn/cloudflare-504) [Cloudflare too many redirects (ERR_TOO_MANY_REDIRECTS)](/errors/cdn/cloudflare-too-many-redirects) [Cloudflare verify you are human loop](/errors/cdn/cloudflare-verify-you-are-human-loop)

More in CDN and hosting errors
[ALB 503 Service Unavailable](/errors/cdn/alb-503) [ALB 504 Gateway Timeout](/errors/cdn/alb-504-gateway-timeout) [API Gateway 403 Forbidden](/errors/cdn/api-gateway-403-forbidden) [API Gateway 504 Gateway Timeout](/errors/cdn/api-gateway-504) [AWS 502 Bad Gateway](/errors/cdn/aws-502-bad-gateway) [AWS Amplify 404 Not Found](/errors/cdn/amplify-404) [AWS EC2: Connection timed out](/errors/cdn/aws-ec2-connection-timed-out) [AWS Lambda 502 Bad Gateway](/errors/cdn/aws-lambda-502) [AWS Lambda timeout](/errors/cdn/lambda-timeout) [Azure Front Door 502](/errors/cdn/azure-front-door-502) [Cloud Run 503 error](/errors/cdn/cloud-run-503) [Cloudflare 504 Gateway Timeout](/errors/cdn/cloudflare-504) [Cloudflare Pages 404 Not Found](/errors/cdn/cloudflare-pages-404) [Cloudflare too many redirects (ERR_TOO_MANY_REDIRECTS)](/errors/cdn/cloudflare-too-many-redirects) [Cloudflare verify you are human loop](/errors/cdn/cloudflare-verify-you-are-human-loop) [CloudFront 400: Bad Request](/errors/cdn/cloudfront-400) [CloudFront 404 Not Found](/errors/cdn/cloudfront-404) [CloudFront 503: Service Unavailable](/errors/cdn/cloudfront-503) [Firebase Hosting 404](/errors/cdn/firebase-hosting-404) [GitHub Pages 404 Not Found](/errors/cdn/github-pages-404) [Google Cloud 502 Bad Gateway](/errors/cdn/google-cloud-502) [Heroku 503 Service Unavailable](/errors/cdn/heroku-503) [Heroku H10: App crashed](/errors/cdn/heroku-h10-app-crashed) [Heroku H12: Request timeout](/errors/cdn/heroku-h12-request-timeout)

Terms on this page
[HTTP status codes](/glossary/http-status-codes) [Soft 404](/glossary/soft-404) [Google Search Console](/glossary/google-search-console) [SPA SEO](/glossary/spa-seo) [JavaScript SEO](/glossary/javascript-seo) [Robots meta tag](/glossary/robots-meta-tag)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
