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 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
TheRequestHeaders collection contains HTTP headers from the incoming request. Headers are automatically mapped based on their name.
| Example | Description |
|---|---|
%{RequestHeaders.Host} | The Host header sent with the request |
%{RequestHeaders.User-Agent} | The User-Agent header |
%{RequestHeaders.Accept-Language} | The Accept-Language header |
Query
TheQuery collection contains URL query parameters. Parameters are automatically mapped based on their key.
For a URL like ?token=abc123&user=42:
| Example | Result |
|---|---|
%{Query.token} | abc123 |
%{Query.user} | 42 |
Request
TheRequest collection contains information about the HTTP request:
| Key | Description | Example |
|---|---|---|
Method | The HTTP method | GET, POST |
Path | Full URL path and query | /videos/test.mp4?quality=hd |
QueryString | Query string only | quality=hd |
Path
ThePath collection allows you to extract specific segments from the URL path using index-based access.
For the path /hello/world/bunny/eat/carrot.jpg:
| Syntax | Result | Description |
|---|---|---|
%{Path.0} | hello | Single segment at index |
%{Path.1} | world | |
%{Path.0-2} | hello/world/bunny | Range from index 0 to 2 |
%{Path.1-3} | world/bunny/eat | Range from index 1 to 3 |
%{Path.3-} | eat/carrot.jpg | From index 3 to end |
%{Path.1-} | world/bunny/eat/carrot.jpg | From index 1 to end |
%{Path.-1} | hello | From start up to index 1 |
%{Path.-3} | hello/world/bunny | From start up to index 3 |
Url
TheUrl collection provides parsed components of the request URL:
| Key | Description | Example |
|---|---|---|
FileName | Filename from the URL (empty for folders) | video.mp4 |
Path | Full URL path and query | /videos/video.mp4?x=1 |
Extension | File extension | mp4 |
Directory | Directory path without filename | /videos/2024/ |
Hostname | Request hostname | cdn.example.com |
User
TheUser collection contains information about the requesting user:
| Key | Description | Example |
|---|---|---|
IP | End-user IP address | 203.0.113.10 |
CountryCode | Two-letter country code | US, DE, JP |
Server
TheServer collection contains information about the serving edge server:
| Key | Description | Example |
|---|---|---|
ZoneCode | Zone code of the serving server | NY, LA, DE |
ID | Unique server ID | 9482 |
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-TokenHeader Value:
%{Query.token}
Geo-based routing
Add the user’s country to the origin request: Header Name:X-CountryHeader Value:
%{User.CountryCode}
Related
- Dynamic Variables - Complete variable reference with all examples
- Rule Ordering - Control execution order for complex rule sets
- Middleware Scripts - For advanced request/response transformations