CDN edge rules
Edge rules change how the CDN handles requests that match a condition, before they reach the cache or the origin. Each rule has a trigger, one or more patterns, and an action. Rules are managed from the Edge rules tab of a CDN.
Rule structure
| Part | What it does |
|---|
| Enable Rule | On by default. Turn it off to save the rule as a draft without activating it. |
| Trigger type | What the rule inspects. See the trigger list below. |
| Pattern matching | Match any: the rule fires if any pattern matches. Match all: every pattern must match. Match none: the rule fires only when no pattern matches. |
| Patterns | One or more values to compare against. * is a wildcard. |
| Action | What happens when the trigger matches. See the action list below. |
| Description | Optional note for your own reference. |
Trigger types
| Trigger | Matches against | Example pattern |
|---|
| URL | The full request URL. | */images/* |
| URL extension | The file extension of the requested path. | jpg |
| Request header | A header sent by the visitor. | Header name and value pattern. |
| Country code | The two-letter country code of the visitor's IP address. | DE |
| Remote IP | The visitor's IP address. | 203.0.113.0/24 |
Actions
| Action | What it does |
|---|
| Redirect | Sends the visitor to another URL with a status code of 301, 302, 307, or 308. The redirect URL can include variables. |
| Override edge cache time | Sets how long the edge keeps the matching content, overriding the origin's Cache-Control. The browser cache time is set to the same value unless an Override browser cache time rule also matches. Applies to content fetched after the rule is created. |
| Override browser cache time | Sets the Cache-Control max-age sent to the visitor's browser. |
| Force SSL | Redirects matching HTTP requests to HTTPS. |
| Block request | Denies the request. |
| Set response header | Adds or overrides a header on the response sent to the visitor. |
| Set request header | Adds or overrides a header on the request sent to the origin. |
| Ignore query string | Treats URLs with different query strings as the same cached object. |
Variables
Redirect URLs and header values can include variables that are replaced per request.
| Variable | Value |
|---|
%{Request.Method} | HTTP method |
%{Request.Path} | Full request path including query string |
%{Request.QueryString} | Query string only |
%{Url.Hostname} | Host portion of the URL |
%{Url.Directory} | Directory portion of the path |
%{Url.FileName} | Filename without extension |
%{Url.Extension} | File extension |
%{Path.0}, %{Path.0-2}, %{Path.3-}, %{Path.-1} | Path segments by index, range, or from the end |
%{Query.name} | Value of the name query parameter |
%{RequestHeaders.Name} | Value of a request header, for example %{RequestHeaders.User-Agent} |
%{User.IP} | Visitor IP address |
%{User.CountryCode} | Visitor country code |
%{Server.ZoneCode} | Edge zone serving the request |
%{Server.ID} | Edge server identifier |
For worked examples, see How to get started with UpCloud CDN.