Skip to main content
Variable expansion allows Edge Rules to dynamically configure values based on specific request parameters. Instead of hardcoding URLs or header values, you can use variables that are replaced at runtime with actual request data.

Supported actions

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

Syntax

Variables are accessed using the following syntax:
%{Collection.Key}
Where Collection is a group of related variables, and Key is the specific value you want to access.
For a complete list of all available variables with examples, see Dynamic Variables.

Variable collections

RequestHeaders

The RequestHeaders collection contains HTTP headers from the incoming request. Headers are automatically mapped based on their name.
ExampleDescription
%{RequestHeaders.Host}The Host header sent with the request
%{RequestHeaders.User-Agent}The User-Agent header
%{RequestHeaders.Accept-Language}The Accept-Language header

Query

The Query collection contains URL query parameters. Parameters are automatically mapped based on their key. For a URL like ?token=abc123&user=42:
ExampleResult
%{Query.token}abc123
%{Query.user}42

Request

The Request collection contains information about the HTTP request:
KeyDescriptionExample
MethodThe HTTP methodGET, POST
PathFull URL path and query/videos/test.mp4?quality=hd
QueryStringQuery string onlyquality=hd

Path

The Path collection allows you to extract specific segments from the URL path using index-based access. For the path /hello/world/bunny/eat/carrot.jpg:
SyntaxResultDescription
%{Path.0}helloSingle segment at index
%{Path.1}world
%{Path.0-2}hello/world/bunnyRange from index 0 to 2
%{Path.1-3}world/bunny/eatRange from index 1 to 3
%{Path.3-}eat/carrot.jpgFrom index 3 to end
%{Path.1-}world/bunny/eat/carrot.jpgFrom index 1 to end
%{Path.-1}helloFrom start up to index 1
%{Path.-3}hello/world/bunnyFrom start up to index 3

Url

The Url collection provides parsed components of the request URL:
KeyDescriptionExample
FileNameFilename from the URL (empty for folders)video.mp4
PathFull URL path and query/videos/video.mp4?x=1
ExtensionFile extensionmp4
DirectoryDirectory path without filename/videos/2024/
HostnameRequest hostnamecdn.example.com

User

The User collection contains information about the requesting user:
KeyDescriptionExample
IPEnd-user IP address203.0.113.10
CountryCodeTwo-letter country codeUS, DE, JP

Server

The Server collection contains information about the serving edge server:
KeyDescriptionExample
ZoneCodeZone code of the serving serverNY, LA, DE
IDUnique server ID9482

Examples

Dynamic origin routing

Route requests to different origins based on the first path segment: Origin URL: https://%{Path.0}.backend.example.com/%{Path.1-} For a request to /api/users/123, this becomes https://api.backend.example.com/users/123.

Pass query parameter as header

Forward a specific query parameter to your origin as a header: Header Name: X-Auth-Token
Header Value: %{Query.token}

Geo-based routing

Add the user’s country to the origin request: Header Name: X-Country
Header Value: %{User.CountryCode}