Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Why Cloudflare Pages Can Ignore Your Redirects and Change Route Results

Cloudflare Pages handles static assets and Function responses differently. Learn how redirects, headers, deployed HTML, route rules, and cache validators affect what a request returns.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cloudflare Pages treats static files and Pages Function responses differently. A _redirects rule does not redirect a request served by a Function, and a _headers rule does not add headers to a Function-generated response. Separately, the files in your deployed output—including a matching HTML file or 404.html—affect how static routes resolve. Those documented behaviors explain many apparent inconsistencies, but they are not measurements of a particular site.

Why can a Pages Function bypass _redirects and _headers?

Cloudflare applies _redirects and _headers to static asset responses. They do not automatically govern a response produced by Pages Functions. If a Function handles a matching request, a redirect written for static assets will not be applied to that Function response, and headers listed in _headers will not be added to it.

As an Amazon Associate I earn from qualifying purchases.

This distinction is about which component serves the response, not simply whether a path appears to match a rule. A Function can return its own response or, if written to do so, fall through to asset serving. If the Function generates the response, implement the needed redirect or headers in the Function. If the static rule should handle the request instead, configure routing so the request is excluded from Functions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate the three response paths

Request outcome What to inspect Documented implication
A matching static asset is served without a Function handling the path Status, Location, and response headers Static _redirects and _headers rules can affect the asset response.
A Function generates the response Whether the Function ran, status, Location, and response headers Static redirect and header rules do not apply to that generated response.
A Function deliberately falls through to asset serving Whether the Function ran and whether the final response came from asset serving Do not assume a rule applied merely because its path pattern matches; verify the response and the Function’s fallback behavior.

Cloudflare documents that redirects run before headers when both static rule files match. A redirect therefore takes priority over a header rule for that request; it is not a way to attach headers to a response generated by a Function.

How can you tell whether the static output is changing a route result?

Pages’ static route behavior depends on the deployed output. A request can match an HTML file, be redirected from an HTML filename to its extensionless URL, use the default single-page-app behavior, or resolve through a custom 404 page. Changing the output files can therefore change the result even when the requested URL stays the same.

  • If a path matches an HTML file, Pages serves that file. Pages also redirects HTML filenames to extensionless counterparts, including /contact.html to /contact and /about/index.html to /about/.
  • By default, Pages supports single-page applications by mapping incoming paths to the root so the client-side app can handle routes such as /about or /help.
  • Deploying a 404.html changes not-found handling. Pages looks for the closest 404 page, moving up the directory tree and ultimately to /404.html.

For a useful comparison, hold the requested path constant and vary the deployed output: first use a matching HTML file, then test without it, then test with a 404.html. Record the status and any Location header. Do not treat an SPA fallback as proof that every unknown path will return the same result when the output or Function routing differs.

How does _routes.json affect whether Function code runs?

Pages uses _routes.json include and exclude rules to control which paths invoke Functions. Exclusions take priority. A static route can be excluded so it does not invoke Function code, which is useful when static files and Function routes coexist. For a Function that needs to serve an asset, Cloudflare’s API reference describes the ASSETS binding as the asset-serving path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cloudflare’s documented constraints are at least one include rule, no more than 100 combined include and exclude rules, and a maximum of 100 characters per rule. These are platform limits, not measurements of an individual deployment.

Test route selection independently

  1. Choose one URL that has a known static asset or fallback result.
  2. Check whether the URL is included or excluded in the deployed _routes.json; exclusions take priority.
  3. Request it with the current routing configuration and record whether Function code ran, along with status, Location, and relevant headers.
  4. Change only the route inclusion or exclusion, deploy again, and repeat the request. This separates a change in Function invocation from a change in the static output.

What should you record when testing these behaviors?

The title of an investigation cannot establish which two behaviors were measured or what a particular project returned. To make a result reproducible, capture the conditions alongside each response rather than inferring behavior from a matching filename or rule.

Condition to record Response evidence
Requested path and deployed output files, including matching HTML and any 404.html Status and Location
Whether _redirects or _headers contains a matching rule Relevant response headers
Whether the path is included or excluded by _routes.json, and whether Function code ran Function-generated response versus asset-serving fallback
Whether the request is a first request or a conditional repeat Etag, request If-None-Match, and status
Deployment time and requesting location or data center, if available Response status and cache-related headers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How should you interpret repeat requests and cache results?

Pages sends Etag headers with 200 responses. A later request can include If-None-Match; when it matches, Pages can return 304 Not Modified so the browser can use its cached copy. That is cache validation, not a redirect.

Cloudflare describes a one-week asset-cache TTL per data center, while noting that assets may disappear earlier. Treat that as a retention description, not a promise that every data center will retain an asset for the full week or share identical cache history. For repeat-request comparisons, note the deployment time and requesting location when available, and record the validator headers as well as the status.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.