Documentation Index
Fetch the complete documentation index at: https://docs.bunny.net/llms.txt
Use this file to discover all available pages before exploring further.
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:
Where Collection is a group of related variables, and Key is the specific value you want to access.
Variable collections
The RequestHeaders 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
The Query 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
The Request 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
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:
| 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
The Url 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
The User 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
The Server 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.
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}