Free auditStart free
GuideError · CDN and hosting

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.

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 withChatGPTClaudePerplexityGoogleAI Mode

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
02How it works

Find out why a path 404s

Build output directory by framework (Cloudflare presets)
Framework or toolBuild commandBuild output directory
Astronpm run builddist
React (Vite)npm run builddist
Next.js (Static HTML Export)npx next buildout
Docusaurusnpm run buildbuild
Hugohugopublic
Jekylljekyll build_site
SvelteKitnpm 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.

03Your 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.
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
04Check 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 and SPA SEO.

Google's 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 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. 01Cloudflare Pages: Serving Pagesdevelopers.cloudflare.com · checked 2026-11-01
  2. 02Cloudflare Pages: Redirectsdevelopers.cloudflare.com · checked 2026-11-01
  3. 03Cloudflare Pages: Debugging Pagesdevelopers.cloudflare.com · checked 2026-11-01
  4. 04Cloudflare Pages: Build configurationdevelopers.cloudflare.com · checked 2026-11-01
  5. 05Cloudflare Pages: Functions routingdevelopers.cloudflare.com · checked 2026-11-01
  6. 06Google Search Central: JavaScript SEO basics (soft 404s in single-page apps)developers.google.com · checked 2026-11-01
  7. 07How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Questions

Asked a lot.

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

01How 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.

02Why 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.

03Why 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.

04Can 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.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane