Skip to content

Routing rules ​

Send some visitors to another destination by country, device, browser, date or click count, and know which rule is checked first.

Routing rules are conditional redirect rules on one short link. A visitor who matches a rule goes to that rule's own destination instead of the link's Destination URL. A rule can look at the visitor's country, device, operating system and browser, at the date, and at how many clicks the link has. Everyone who matches no rule goes to the link's usual destination.

How do routing rules pick a destination? ​

On every visit, Link Manager Pro checks the link's active rules from the lowest Priority number up and uses the first rule that matches. That rule's Destination URL and Redirect type win. If no rule matches, the visitor gets the link's own destination and redirect type, as if the link had no rules.

A rule matches when both of these are true:

  1. Today is inside its Between dates, if it has any.
  2. Its conditions are met: every condition with All conditions, at least one with Any condition. A rule with no conditions matches everyone.

Rules with Active turned off are skipped. Two rules with the same Priority are checked in the order the form lists them.

Here's an example. The short link yoursite.com/link/shoes has the destination https://example.com/shoes and two rules:

PriorityNameConditionDestination URL
10UK storeCountry in GBhttps://example.co.uk/shoes
20PhonesDevice in Mobilehttps://m.example.com/shoes

A visitor in the UK on a phone matches both, so the Priority 10 rule wins and they go to the UK store. A visitor in Canada on a phone goes to the mobile page. A visitor in Canada on a laptop matches nothing and goes to https://example.com/shoes.

Add a routing rule ​

You add rules in the short link's edit form, in the Routing rules group.

Link Manager › Short Links
  1. Select the Edit icon (the pencil) in the link's row. Edit short link opens.

  2. Turn on the switch on the Routing rules row. It's already on when the link has rules.

  3. Select Add rule.

  4. Enter a Name you'll recognize later, like UK store. It's optional, and visitors never see it.

  5. Set Priority. Lower numbers are checked first.

  6. Enter the rule's Destination URL, starting with https://, and choose its Redirect type.

  7. Select Add condition. Choose its Type first, then its Operator and Value. Repeat for each condition.

    Note

    A new condition starts as Clicks >= 0, which every visitor meets. Change its Type and Value before you save, or the rule sends everyone to its destination.

  8. With two or more conditions, choose All conditions or Any condition under Match when.

  9. To limit the rule to a date range, pick a start and an end date under Between.

  10. Select Save changes.

The rule works from the next click. To check it, open the link's report. Under At a glance, the Routing rules row shows how many rules are active and describes the first two in plain words, like "When country is US, CA". Then open the short link from a device or place the rule should catch. Your own test clicks count like anyone's, so they also raise the number a Clicks condition looks at (Does your own test count as a click?).

The Routing rules group of the Edit short link dialog, showing the first of its two rules, marked: 1 Priority, 2 Match when set to All conditions, 3 Between with no dates, 4 Conditions Country in US,CA and an After date
A rule with two conditions that must both match: Country in US,CA and an After date.

The parts of a rule ​

Each rule has its own destination, redirect type, place in the order and optional date range. These are the fields and what a new rule starts with.

FieldStarts asWhat it does
NameEmptyYour label for the rule, up to 120 characters
Priority1000 to 100. Lower numbers are checked first. A cleared field saves as 100, and a typed 0 is kept
Match whenAll conditionsAll conditions: every condition must be met. Any condition: one is enough
ActiveOnOff keeps the rule but skips it
Destination URLEmpty (required)Where matching visitors go: a full http:// or https:// address, up to 2,048 characters
Redirect typeThe link's own Redirect type301, 302 or 307, for the visitors this rule sends
BetweenNo datesThe rule applies only from the start date to the end date (Dates and your site's time zone)
ConditionsNoneWhat the visitor must match (the conditions). No conditions means every visitor

A few things the form doesn't tell you:

  • Turning off the switch on the Routing rules row only hides the group. The rules stay saved and keep working. To stop a rule, turn off its Active switch or select Remove rule, then save.
  • Rules belong to short links. A redirect under Link Manager › Link Intelligence › Redirects has none (Redirects).
  • Deleting a short link deletes its rules with it. A backup can include them under Routing rules (Back up and restore).

Conditions: redirect by country, device, browser, date or clicks ​

A condition compares one thing about the visit with a value you set. These are the seven condition types and what each one accepts.

TypeOperatorValueThe condition is met when
Clicks>=, >, =, < or <=A whole number, 0 or moreThe link's All-time clicks, counting this visit when it's counted, compare that way with the number
CountryinTwo-letter country codes separated by commas, like US,CA,GBThe visitor's country is one of them
DeviceinOne or more of Desktop, Mobile, Tablet, OtherThe visitor's device type is one of them
Operating systeminOne or more of Windows, macOS, iOS, Android, Linux, OtherThe visitor's system is one of them
BrowserinOne or more of Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, OtherThe visitor's browser is one of them
After>= or >A date>=: from the start of that day. >: from the start of the next day
Before<= or <A date<=: until that day ends. <: until that day starts

How the values behave:

  • Country takes two-letter ISO codes, so GB for the United Kingdom, not UK. Lowercase is fine: codes are saved in capitals. A code that isn't two letters is refused when you save. While the visitor's country is unknown, a Country condition is never met.
  • Device, Operating system and Browser take one or more values from their list. A visitor matches if they match any value you picked.
  • Clicks uses the same counter as the All-time clicks column in Short Links, so clicks from before you added the rule count too. With Clicks <= 100, the first 100 counted clicks go to the rule's destination, and everyone after that to the next rule or the default.
  • The counter keeps going up while Click tracking is off. Some visits don't raise it: bots and crawlers while Ignore bots is on, addresses in Blocked IP addresses, browser background loads (preloads and prefetches) and HEAD requests. Neither do clicks past the 30th in 5 minutes from one IP address (How clicks are counted). Your rules still route these visitors, except a background load, which gets no redirect at all and is loaded again when the person follows the link.

How the country, device and browser are found ​

The country comes from your CDN or from the country database. Device, operating system and browser come from the name the visitor's browser sends with each visit, called its user agent. All of these are good hints, not proof.

The country is found in this order:

  1. A two-letter country header from your CDN or proxy: CF-IPCountry (the one Cloudflare sends), then X-Country-Code. A value of XX or ZZ means no country, so it goes on to the next header and then to the database. Link Manager Pro reads them only when Trust proxy headers is on, or when the visit comes from an address in Trusted proxy IPs or CIDR ranges. Once that list holds anything, only visits from its addresses count, whatever the switch says. Behind Cloudflare, it recognizes Cloudflare's published addresses by itself and reads only CF-IPCountry, with no setting needed (Trust proxy headers).
  2. The GeoIP country database, once you've downloaded it under Link Manager › Settings › Tracking and your site runs PHP 8.1 or later (System requirements).

With neither, the country is unknown and Country conditions never match. Either way, the country is where the visitor's IP address is located. A visitor on a VPN or a proxy service gets that service's country. Behind a CDN that isn't trusted, the database looks up the CDN's address, so many visitors can get the same country.

Device, operating system and browser are sorted like this:

ValueWhat counts
TabletiPads that report themselves as iPads, Kindle and Silk browsers, anything that calls itself a tablet, and Android devices that don't say they're mobile
MobileiPhones, iPods, Android phones, BlackBerry, Opera Mini, and other browsers that say they're mobile or a phone
DesktopWindows, Mac, Linux and Chrome OS computers
Other (device, operating system and browser)Anything not recognized, plus bots, crawlers and link previews whose name contains bot, crawl, spider, slurp or preview
BrowserChecked in this order: Edge, Opera, Samsung Internet, Firefox, Chrome, Safari. Chrome and Firefox on an iPhone count as Chrome and Firefox

Some limits to plan for:

  • Safari on an iPad usually reports itself as a Mac, so it counts as Desktop and macOS. Don't count on Tablet to catch iPads.
  • Other browsers that send the same name as Chrome count as Chrome.
  • Anyone can change the name their browser sends, so don't use these conditions to protect anything.

Dates and your site's time zone ​

Between, After and Before work in whole days, in the time zone set under Settings › General in WordPress. The switch happens at midnight there, not at midnight where your visitor is.

  • Between gives you scheduled affiliate links: the rule sends visitors to another destination only on those dates, and the link goes back to normal after the last day.
  • Between runs from the start of the first day to the end of the last day. A sale set to November 27 to November 30 starts at 00:00 on November 27 and ends when December 1 begins.
  • Between needs both dates. For a rule with only a start, use an After condition. For one with only an end, use Before.
  • Between always applies, whatever Match when says. After and Before are conditions, so with Any condition another condition can match without them.
  • Rules imported from ThirstyAffiliates or BetterLinks can carry an exact time. They switch at that time, though the form shows only the date (From BetterLinks).

TIP

Running a sale? Run Black Friday and other sale links walks through a dated rule from start to finish.

What else applies when a rule matches ​

A matched rule changes only the destination and the redirect type. Everything else about the link works as usual.

  • UTM parameters and forwarding: your site-wide UTM parameters, the link's UTM parameters and forwarded query parameters go on the rule's destination. An affiliate's UTM parameters are added only when the link's Destination URL and the rule's destination are both on the affiliate's domain (UTM parameters and forwarding).
  • Passwords: on a password-protected link, visitors enter the password first, then the rules run.
  • Scheduled and expired links: before Starts or after Expires, the link doesn't answer at all, so no rule runs either. A rule with Between dates is different: the link keeps working outside them.
  • Other addresses: a visit through one of the link's other addresses gets the same rules.
  • Caching: each short link visit is marked not to be cached, so the rules run on every visit. A host or CDN cache that ignores those marks can hand out a stored redirect instead (Integrations settings).
  • Affiliate clicks: an affiliate's click count follows the domain of the link's Destination URL, even when a rule sends the visitor somewhere else.
  • Link Health: scans check only the link's main Destination URL, not rule destinations (Link Health).

Where routing rules show in reports ​

A link's report shows which rules the link has, but no report counts clicks per rule.

  • At a glance has a Routing rules row that counts the active rules, like "Routing rules · 2 active". When some are off, it reads like "Routing rules · 1 of 3 active". "Active" means the rule's Active switch is on and its Between dates haven't ended. It lists the first two active rules in the order they're checked: each rule's condition in words, its destination and its redirect type. More rules show as a line like "+3 more".
  • Link details shows Routing rules with the total, like "2 rules", or None.
  • Each recorded click notes the rule that matched, but no chart or table shows it. Saving a link's rules again replaces them all, so older clicks no longer point to a rule that exists.

Link report covers the rest of the report.

Get more out of it ​

  • Send each country to its own store. Keep your main store as the link's Destination URL. Add one rule per regional store, like Country in GB,IE to https://example.co.uk/shoes and Country in DE,AT,CH to https://example.de/shoes. Download the GeoIP database first, or trust your CDN's header, or the rules never see a country.
  • Send phones to the right app store. Add a rule with Operating system in iOS to your App Store page and one with Operating system in Android to your Google Play page. Your website stays the default for everyone else. The operating system catches iPhones and Android phones whatever browser they use. A crawler counts as Other, so it isn't sent to an app store.
  • Number your rules 10, 20, 30. The gaps let you slot a rule in later without renumbering.
  • Run a limited offer. Clicks <= 200 sends the first 200 counted clicks to the offer, and the rest to the next rule that matches, or the default. A rule with only Between dates sends everyone to a sale page for those days, then the link goes back to normal (Create and edit a short link).
  • Tell your rules apart in your own analytics. Since no report counts clicks per rule, add a marker to each rule's destination, like ?ref=uk-rule. Pick a name your Site-wide UTM parameters don't use. With Forward query parameters on, a visitor's own ref replaces yours.

If something goes wrong ​

  • If a Country rule never matches, then Link Manager Pro may have no country for your visitors. Download the GeoIP database under Link Manager › Settings › Tracking (PHP 8.1 or later). Or trust your CDN's country header under Link Manager › Settings › Advanced. Also check that you used GB, not UK.
  • If every visitor goes to a rule's destination, then that rule has no conditions, or still has the starting condition Clicks >= 0. Give it a real condition, or turn its Active switch off while you fix it.
  • If a rule seems to be ignored, then check its Active switch and its Between dates, in your site's time zone. Also check whether a rule with a lower Priority matches first. A host or CDN cache can also answer before WordPress does.
  • If saving shows a message under Value, then a condition has a value the server can't use. The message names the condition in a full sentence, like Clicks must be 0 or more., Pick at least one country., Use 2-letter country codes, like US. or Device: pick at least one value. A date problem says Date condition requires a valid datetime value. A Priority outside 0 to 100 says Use a number from 0 to 100. Enter two-letter country codes, pick at least one value in the list, enter a number, or choose a date.