> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.divert.ly/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.divert.ly/_mcp/server.

# Target Selection

> Exactly how a Divertly route picks a target: strategies by plan, matching rules, first-match-wins, and fallbacks.

Every time someone visits a route, Divertly runs the route's [targeting strategy](/docs/concepts/routes#targeting-strategies) against the request and picks one [target](/docs/concepts/targets). This page spells out the rules, including what happens when more than one target matches, or none do.

## Availability by plan

| Strategy         | Free | Paid |
| ---------------- | ---- | ---- |
| Weighted         | Yes  | Yes  |
| Random           | Yes  | Yes  |
| Country          |      | Yes  |
| Language         |      | Yes  |
| Device Type      |      | Yes  |
| Browser          |      | Yes  |
| Operating System |      | Yes  |
| HTTP Header      |      | Yes  |
| Query String     |      | Yes  |
| User Agent       |      | Yes  |
| Human vs. Bot    |      | Yes  |
| IP CIDR          |      | Yes  |

Weighted and Random are available on every plan. The other strategies are available on paid plans. You can list the strategies your organization can use from the `targetStrategies` field of the [entitlements endpoint](/docs/organization/subscriptions#check-your-limits-and-usage-programmatically).

## The resolution rules

1. **A route with no targets** has nowhere to send the visitor, and the request returns an error.
2. **A route with exactly one target** sends every visitor to it, whatever the strategy.
3. **Otherwise the strategy runs**, as described below.
4. **If the strategy finds no match**, the route's [fallback](#when-nothing-matches) applies.

## Weighted and Random

* **Random** picks any target with equal probability.
* **Weighted** picks a target in proportion to its weight. A target with weight 90 and one with weight 10 receive roughly 90% and 10% of traffic. A target with a weight of 0 is never chosen while another target has a weight above 0. If every weight is 0, the route picks at random instead.
* Weighted routes can be made **sticky**, so a returning visitor keeps landing on the same target. Sticky behavior is set with the `sticky` field when you update a route through the API.

## Match-based strategies

Country, Language, Device Type, Browser, Operating System, HTTP Header, Query String, and User Agent compare an attribute of the request with each target's match value:

| Strategy         | What the request is compared with                                                                    |
| ---------------- | ---------------------------------------------------------------------------------------------------- |
| Country          | The visitor's country, as a two-letter ISO code (for example `US`), looked up from their IP address. |
| Language         | The `Accept-Language` header.                                                                        |
| Device Type      | The device type parsed from the user agent.                                                          |
| Browser          | The browser name parsed from the user agent.                                                         |
| Operating System | The operating system parsed from the user agent.                                                     |
| HTTP Header      | The value of the header named in the route's **Targeting Selector**.                                 |
| Query String     | The value of the query-string parameter named in the route's **Targeting Selector**.                 |
| User Agent       | The full user-agent string.                                                                          |

How matching works:

* A target's match value is treated as a **regular expression**, and matches if it appears **anywhere** in the request's value. Matching is case-sensitive. `en` matches the language header `en-US,en;q=0.9`, and `Chrome` matches any user agent containing `Chrome`. To match exactly, anchor the pattern with `^` and `$`.
* Targets are checked in turn, and **the first matching target wins**. If your match values can overlap, a request may match several targets, so write them so that they don't.
* A target whose match value isn't a valid regular expression is skipped.
* If the request doesn't carry the attribute at all, such as a missing header, a missing query parameter, or an IP address whose country isn't known, nothing matches and the fallback applies.

> **Note**
>
> Pick match values from the preset list when the dashboard offers one, for Country, Device Type, Operating System, Language, and Browser. These are already in the form the strategy expects.

## Human vs. Bot

Each request is classified as a human visitor or automated traffic. A target's match value is **Humans**, **Bots**, or **Any**. A human request considers targets set to Humans or Any, and a bot request considers targets set to Bots or Any. If more than one qualifies, one is chosen at random. See [Redirect Bot Traffic](/docs/user-guides/redirect-bot-traffic).

## IP CIDR

A target's match value can be a single IPv4 address (`203.0.113.7`), a CIDR range (`203.0.113.0/24`), or several of these separated by commas (`203.0.113.0/24, 198.51.100.7`). The request matches when the visitor's IP address falls in any of them. Targets are checked in turn and the first match wins.

## When nothing matches

The route's **Targeting Fallback** decides what happens:

| Fallback | Result                                                                                                                           |
| -------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Resolve  | The visitor goes to the route's **Default Target**. If no default target is set, one of the route's targets is chosen at random. |
| Error    | The visitor receives an error.                                                                                                   |

## Changes take effect immediately

Selection runs on every request, so changing a strategy, a match value, a weight, or whether a target is enabled applies to the next visit. There's nothing to publish.