By utilizing dynamic destinations, you can define complex traffic routing rules based on your incoming traffic. Available from our Pro plan and up.
Dynamic destinations operate by defining multiple destinations on a single redirect, each with a unique expression. This expression determines if the destination should be used for the incoming request.
For example, do you wish to redirect all US traffic to 'new-website.us', and all other traffic to 'new-website.com'? Or perhaps you desire to redirect all traffic before 12:00 to Destination A, and afternoon traffic to Destination B? These configurations are achievable by defining custom expressions.
This support article explains the available options which can be used in your expression.
Parameters
You may use all destination variables as parameters in your expression, for instance:
domain.fqdn - example: www.redirect-me-plz.co.uk
domain.label - example: www.redirect-me-plz
domain.root - example: redirect-me-plz
domain.extension - example: co.uk
domain.subdomain - example: www
path - example: contact
country - example: US
method - example: POST
userAgent - example: Mozilla/5.0 (iPad; U; CPU.....)
scheme - example: https
See all destination variables that can be used here.
You can also use regex capture groups:
$1 // Regex capture group 1
$2 // etc.
On top of these variables, the following functions are available:
now() // UTC unix timestamp to be used to compare dates or time
time('15:00') // UTC timezone
time('15:00', 'Europe/Amsterdam') // Specify timezone via second parameter
datetime('2023-01-01') // UTC timezone
datetime('2023-01-01 15:00') // UTC, with time
datetime('2023-01-01 15:00', 'Europe/Amsterdam') // Amsterdam timezone
Date comparision
You can define date objects with the `datetime` function:
datetime('2023-01-01') < time()
The code above uses the UTC timezone. If you wish to specify your own timezone, you can wrap the date (with or without time) in the `datetime` method:
datetime('2023-01-01 15:00', 'America/New_York') // Specify timezone via second parameter
Random comparison
To steer traffic on a random basis, you can use the random function. This method accepts `min` and `max` integer values, which you can compare. For example, if you want to redirect 70% of the traffic to destination A and 30% to destination B, you can use the following approach:
random(1, 100) <= 70
Expression
The order of the defined destinations are important. The first expression that matches the incoming request will be used. To match all requests for a "fallback" destination, you keep the expression empty. An empty expression will always result in a match.
The expression is evaluated by the powerful golang `expr` package. Read more about the many options here.
Examples
Example 1
Source: source.com
Destination 1:
URL: destination.us
Expression: country == 'US'
Destination 2:
URL: destination.com
Expression: ''
When traffic from the US comes in, the visitor is redirected to destination.us. All other traffic will match the expression '*', and is redirected to destination.com.
Example 2
Source: source.com
Destination 1:
URL: launching-soon.com
Expression: datetime('2023-01-01 12:00', 'America/New_York') > now()
Destination 2:
URL: new-website.com
Expression: ''
When traffic before the 1st of January 2023 and 12:00 NY timezone comes in, it's redirected to launching-soon.com. Traffic after the 1st of January 2023 and 12:00 NY time, will be redirected to the new-website.com
Example 3
Source: source.com
Destination 1:
URL: destination-before-12.com
Expression: time('12:00') < now()
Destination 2:
URL: destination-after-12.com
Expression: time('12:00') >= now()
When traffic before 12:00 comes in, the visitor is redirected to destination-before-12.com. Traffic after 12:00 will be redirected to destination-after-12.com.
Time is automatically determined based on the UTC timezone. You may define a second parameter to the `time` function to specify your local timezone for easier readability.