How do Cloudflare Pages redirects handle query strings?

The Citead team, updated

In short. Cloudflare Pages preserves the incoming query string unless the redirect destination supplies its own query string.

Definition: A query string is the URL component introduced by ?, as defined in RFC 3986. As of 17 October 2026, Cloudflare Pages' redirect tests establish that an incoming query string is preserved when the destination has no query string, while a destination query replaces the incoming one.

Key facts

  • Cloudflare's Pages tests check that /?sort=price redirects to /home?sort=price when the rule points to /home.
  • The Pages redirects guide allows query strings in destinations and gives /querystrings /?query=string 301 as an example.
  • The Pages redirect handler applies the same choice between destination and incoming query strings to destinations on the same origin and on another origin.
  • Cloudflare's redirect verification instructions use curl to inspect the response's location header and status code.

When is an incoming query preserved or replaced?

Cloudflare describes pages-shared as code used by its Pages infrastructure. Its query-preservation test supplies these rules, expressed here in _redirects syntax:

/ /home 301
/recent /home?sort=updated_at 301

The test checks the following outcomes. Location is the response header containing the redirect destination.

Incoming requestExpected Location
https://example.com/?sort=price/home?sort=price
https://example.com/recent/home?sort=updated_at
https://example.com/recent?other=query/home?sort=updated_at

The last row shows replacement: other=query disappears when the destination supplies sort=updated_at. The handler selects the destination query when it is nonempty and otherwise uses the incoming query; it does not merge the parameter sets.

What can the destination contain?

The Pages redirects guide defines each line as a source path, a destination, and an optional status code. The destination can be a file path or an external link, and it can contain query strings and fragments, the URL components introduced by #.

The guide also shows path placeholders, named values captured from the source path, being inserted into destination parameters:

/products/:code/:name /products?code=:code&name=:name

Here, :code and :name come from path segments. The guide marks query-parameter matching as unsupported. Selecting a rule according to an incoming parameter value therefore falls outside the documented _redirects matching features.

Cloudflare's handler tests also check an external destination containing a fragment. A request to https://foo.com/bar?test=abc, redirected to https://foobar.com/#heading, produces https://foobar.com/?test=abc#heading: the preserved query appears before the fragment.

How can the deployed destination be checked?

Cloudflare's Pages verification guide recommends inspecting the location header and status code with curl. For the example rules above, replacing the example domain with the deployed domain gives these checks:

curl --head -i 'https://example.com/?sort=price'
curl --head -i 'https://example.com/recent?other=query'

The headers can then be compared with the table. These commands are a verification procedure; the table records Cloudflare's test expectations.

The Pages redirects guide excludes requests served by Pages Functions from _redirects processing. For those routes, redirect behavior belongs in the Function code, or the route must be excluded from Functions so static rules can apply.

FAQ

Can I add a fixed query string to a destination?

Yes. Cloudflare's redirects guide includes /querystrings /?query=string 301. Under the Pages handler's selection logic, that destination query replaces any incoming query.

Can I preserve the incoming query when redirecting to another domain?

Yes. The Pages handler uses the incoming query for an external destination when the destination has no query string. An explicit destination query takes precedence.

Does omitting the status code change the query rule?

The Pages redirects guide sets the default status code to 302. The handler selects the query string before choosing the response status.

Sources

  1. IETF, "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax", January 2005
  2. Cloudflare, "Redirects", 25 August 2026
  3. Cloudflare, "pages-shared README", repository snapshot 16 October 2026
  4. Cloudflare, "Pages asset-server handler tests", repository snapshot 16 October 2026
  5. Cloudflare, "Pages asset-server handler", repository snapshot 16 October 2026
  6. Cloudflare, "Redirecting www to domain apex", 21 April 2026

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark