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 fromdomain.com to www.domain.com while preserving the path:
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:Related
- Variable Expansion - Detailed syntax reference for variable collections
- Trigger Path Setup - Configure trigger conditions correctly
- Middleware Scripts - For complex transformations beyond Edge Rules