The list of dynamic variables in the Edge Rule redirect URL

This guide explains the most common Edge Rule variables available and how to use them, with examples to help you build effective rules.

Edge Rules allow you to create powerful custom behaviors, like redirects, header modifications, or origin changes based on the incoming request. To make these rules dynamic and flexible, you can use variables that automatically adapt based on request data.

Variable expansion works in rules like:

  • Redirect to URL
  • Change Origin URL
  • Set Request Header
  • Set Response Header

You can mix these variables into your custom value using:

%{Collection.Key}

How to Access Edge Rules:

Navigate to CDN → Select your desired Pull Zone → Go to the Edge Rules tab.

00227f55-4580-4042-912b-f419af144bd5.png
 

Basic Variables

These are some of the most common and easy-to-use variables for general redirection and header logic

Variable

 

Description

 

Example Output

 

{{path}}

Full request path including query string

/videos/test.mp4?user=1

{{hostname}}

The hostname from the request

test.b-cdn.net

{{country_code}}

Two-letter country code of the user’s IP

US

{{query_string}}

Only the query string part (excluding the question mark ?)

user=1

{{request_method}}

HTTP method used

GET, POST

{{file_name}}

Filename from the URL (last part after /)

file.jpg, test.mp4

 

These are mostly used in older rules or simplified setups.

Examples:

Usage Tip: The {{ }} variable placeholders automatically include slashes where needed in URLs, so you don’t need to manually add / before or after them.

dd1be664-487a-489c-99c8-f195b6ca44a5.png
146edf1b-c318-4159-9d96-c6bd86f9e9fb.png
 
 

Advanced Variable Collections

The new variable system allows for more flexible and detailed access to request data using this syntax:

%{Collection.Key}

Note: When using these variable formats, you’ll need to manually include the / slashes in your URLs where appropriate, just like in the example images.

The example images are meant to illustrate how variables can be used. The way you combine and apply them may vary depending on your specific use case.


RequestHeaders

Access headers from the incoming HTTP request.

Example

Result

%{RequestHeaders.Host} videos.example.com
%{RequestHeaders.User-Agent} Browser or client info
 

Example Usage:

2fa64e45-f303-46c0-95ed-55898e1fb97b.png

 


Query

Access specific query parameters in the URL.

 

URL Example

 

Variable

 

Result

 

/video.mp4?user=123

%{Query.KeyName}

123

 

Example Usage:

The "KeyName" field must be replaced with the key of your query so that the system obtains its value. So if your query is called "Myhash" and has a value of "123", for the system to obtain this value, you must call it like this: %{Query.Myhash}. 

cbb9b1ed-858f-485f-8017-fdb163c54ca1 (1).png
 

Path

Extract specific segments of the URL path. Useful for complex routing or origin overrides.

Example path: /hello/world/bunny/eat/carrot.jpg

 

Variable

Output

%{Path.0} hello
%{Path.1} world
%{Path.0-2} hello/world/bunny
%{Path.1-3} world/bunny/eat
%{Path.3-} eat/carrot.jpg
%{Path.1-} world/bunny/eat/carrot.jpg
%{Path.-1} hello/world

Note: If the URL includes a query string and the path you extract doesn’t alter or truncate the filename, the query string will remain intact. For example:

If your path is:

/hello/world/bunny/eat/carrot.jpg?query=something

and you use: %{Path.1-} The result will be: world/bunny/eat/carrot.jpg?query=something

Example Usage:

4e595ced-0544-4ece-9e89-7f7529b88ad4 (1).png
 

Url

Breaks down parts of the full URL

Key

 

Description

 

Example

 

%{Url.Filename}

Last part of URL. If the request is to a folder, this will remain empty

video.mp4

%{Url.Extension}

File extension

mp4

%{Url.Directory}

Folder path only

/videos/2024/

%{Url.Hostname}

Hostname from request

cdn.mysite.com

%{Url.Path}

Full path and query

/videos/video.mp4?x=1

Example Usage:

59b31af9-64b4-46fb-b9dd-6202683fae72 (1).png
 

User

Info about the user making the request.

Key

 

Description

 

Example

 

%{User.IP}

End-user IP address

203.0.113.10

%{User.CountryCode}

Country of the request

DE

Example Usage:

52689aa0-eca1-4c05-bae3-94ededcbb350 (1).png
 

Server

Internal info about the server processing the request.

Key

 

Description

 

Example

 

%{Server.ZoneCode}

Code of the serving zone

NY

%{Server.ID}

Server ID

9482

Example Usage:

d076203e-dc17-40f1-bdce-9d8c08ffadb9 (1).png
 

Practical Example: Domain redirects to www


If you want to automatically redirect all requests from domain.com to the www.domain.com version, while preserving the full path, you can use the following Edge Rule.

For example:

domain.com/test-website → www.domain.com/test-website

Rule Configuration:

  • Rule Type: Redirect to URL
  • Value: https://www.domain.com{{path}}
  • Status Code: 301
  • Condition: Request URL
  • Condition Value: *

Important:

This rule must be added to the pull zone where domain.com is declared, not where www.domain.com is

If both domain.com and www.domain.com are declared as hostnames in the same pull zone, you can narrow the redirect condition using:

*://domain.com*

This ensures the redirect only applies to the non-www version.

 
 

References

For more in-depth documentation and updated examples, visit:

Edge Rules Variable Expansion Documentation

Table of Contents

Was this article helpful?
2 out of 2 found this helpful