Skip to main content
aapp-hacks
← Back to articles
Author
app-hacks
Published
Updated
Reviewed

Astro / Cloudflare Pages / HTTP

Why Missing URLs Can Return 200 on Cloudflare Pages and How Astro Handles 404s

A record of adding an Astro 404 page and verifying both the visible error screen and the HTTP status in production.

A dedicated error screen does not prove that a missing URL returned HTTP 404. Hosting fallbacks and application routing can serve a home page with 200 OK for an unknown path. Because the visitor still sees a page, verify the interface and HTTP status separately.

This repository added src/pages/404.astro in commit 0f52fb4. The component shows that the page was not found and links back to the home and article list, giving visitors a useful next step.

What to verify on a static site

Astro’s src/pages/404.astro defines the built error page. The hosting environment determines the final response status. The production check for this site confirmed HTTP 404 for a missing path; that result applies to this site’s published configuration, not every Cloudflare Pages setup.

<!-- src/pages/404.astro -->
<h1>Page not found</h1>
<a href="/en/">Back to home</a>

The rendered browser screen alone cannot distinguish 200 from 404. Inspect the final response with the browser Network panel or an HTTP client. If redirects occur, record the final URL and final status rather than an intermediate response.

Common failure points and the chosen approach

A branded 404 screen served with status 200 can look like a valid page to search engines and monitoring tools. A technically correct 404 with no route onward is also poor for visitors. This site uses two checks: define the page in Astro, then confirm HTTP 404 in production.

After adding articles, run npm run build to ensure the 404 output is present. After production deployment, test one deliberately nonexistent path. Do not use a real article URL as the probe, which could measure a cached normal page.

The same distinction applies when repairing links: confirm the old URL returns 404 and the new URL returns 200. Automatically redirecting every 404 to home hides the reason and blurs HTTP semantics. This site states the problem and lets the visitor choose a valid destination.

The 404 page uses the shared layout for consistent navigation and base metadata, but it does not add ads or links to nonexistent content. Error states need a clear explanation and valid recovery route rather than the full density of a normal article.