Advertising disclosure: We may earn a commission from links on this site. Commercial relationships can affect placement. Product facts, limitations, and source dates remain part of our editorial record.

How funding works
Web Hosting

Cloudflare Query String Sort: A Guide for Website Owners

Learn how Cloudflare’s Query String Sort Cache Rule handles cache keys, where to enable it, and what to test before using it.

Review sources
Research standard

Facts that can change should include a source and check date. Benchmark claims should state the plan, region, method, and test period.

Cloudflare’s Query String Sort is the Cache Rule setting to use when a resource is requested with the same query parameters in different orders and you want Cloudflare to sort those parameters for caching. In the rule, go to Cache key, turn on Sort query string, and apply it only where parameter order does not change the response your site intends to serve.

What Query String Sort changes#

Query String Sort handles query-string parameters for caching purposes. When parameter names and values are the same but appear in a different order, sorting gives Cloudflare a consistent order for cache-key handling.

This setting concerns Cloudflare’s cache behavior. It does not determine how your application interprets query strings, so confirm that reordering parameters is safe for the URLs covered by the rule. If parameter order can change the intended response, do not apply Query String Sort to those requests.

Cloudflare’s documented configuration#

Cloudflare’s example uses a custom filter that matches a hostname. Configure the Cache Rule with:

  • Expression Builder: Hostname contains "example.com"
  • Expression Editor: (http.host contains "example.com")
  • Cache eligibility: Eligible for cache
  • Cache key: Turn on Sort query string

Replace example.com with the hostname you intend to cover. Keep the filter limited to requests for which sorted query parameters are safe. The documented example combines hostname matching, cache eligibility, and the cache-key setting; review each part before applying the rule.

Checks before enabling it#

  1. Identify the URLs where the same query parameters may arrive in different orders.
  2. Confirm that changing only the parameter order does not change the response your application is meant to return.
  3. Scope the rule to the appropriate hostname or narrower request pattern.
  4. Set the matching requests as Eligible for cache if they should be cached.
  5. Enable Sort query string under Cache key.
  6. Validate representative requests after the rule is applied. This is a site-specific check; this guide does not report a test result.

Cloudflare’s broader cache documentation explains that Cache Rules specify which resources should be cached and for how long. Query String Sort is a cache-key option, so enabling it does not by itself define the cache duration for a resource.

This guide describes Cloudflare’s implementation. Equivalent settings and behavior may differ with other hosting or CDN providers.

Sources

  1. Cloudflare: Query String Sort Checked 2026-11-22
  2. Cloudflare cache documentation Checked 2026-11-22