Skip to main content
Edge Rules support dynamic variables that automatically adapt based on request data. These variables allow you to create flexible rules for redirects, header modifications, and origin changes.

Supported actions

Variable expansion works in the following Edge Rule actions:
  • Redirect to URL
  • Change Origin URL
  • Set Request Header
  • Set Response Header

Variable syntax

There are two variable syntaxes available:
The {{ variable }} syntax automatically includes slashes where needed in URLs. When using %{Collection.Key} syntax, you need to manually include slashes in your URLs.

Basic variables

These simple variables are commonly used for general redirection and header logic:

Example: Redirect preserving path

To redirect all requests from one domain to another while preserving the path:

Advanced variable collections

The advanced variable system provides detailed access to request data using the %{Collection.Key} syntax.

RequestHeaders

Access headers from the incoming HTTP request.

Query

Access specific query parameters from the URL. For a URL like /video.mp4?user=123:
Replace KeyName with your actual query parameter name. For example, if your query is ?Myhash=123, use %{Query.Myhash} to get 123.

Path

Extract specific segments of the URL path. This is useful for complex routing or origin overrides. For the example path /hello/world/bunny/eat/carrot.jpg:
If the URL includes a query string and the path you extract doesn’t alter the filename, the query string remains intact. For example, with /hello/world/bunny/eat/carrot.jpg?query=something, using %{Path.1-} returns world/bunny/eat/carrot.jpg?query=something.

Url

Access parsed components of the full URL.

User

Information about the user making the request.

Server

Internal information about the server processing the request.

Request

Information about the HTTP request.

Practical examples

Redirect non-www to www

Redirect all requests from domain.com to www.domain.com while preserving the path:
This rule must be added to the pull zone where domain.com is declared, not where www.domain.com is declared.If both hostnames are in the same pull zone, narrow the condition to *://domain.com* to only match the non-www version.

Route requests based on path segment

Route requests to different origins based on the first path segment: This would route /api/users/123 to https://api.example-backend.com/users/123.

Add country code to request header

Pass the user’s country to your origin for geo-based logic:
Last modified on June 26, 2026