Redirect path selection algorithm
How SiteDetour picks which path rule to apply to an incoming request, and why the longest match wins.
Overview
When a redirect has multiple path rules, SiteDetour picks the single best match using a deterministic algorithm. This article documents that algorithm and the rationale behind it.
Request sanitization
Before matching, SiteDetour strips the incoming URL down to just its path:
- Scheme (
http://orhttps://): dropped. - Host: dropped.
- Query string: dropped from the match input but preserved for forwarding.
- Fragment (
#...): never sent by the browser.
So a request for https://example.com/blog/post-1?utm=twitter matches on /blog/post-1.
Match operators
Each path rule uses one of two operators:
- Exact Match — the request path must equal the rule path character-for-character.
- Starts With — the request path must begin with the rule path.
Selection rules
SiteDetour walks every rule in the redirect:
- For Exact rules, it checks for a precise string equality. If an Exact rule matches, it's a candidate.
- For Starts With rules, it checks whether the request path starts with the rule's path. If so, the rule is a candidate; its "match length" is the length of the rule's path in characters.
- Among candidates, the longest match wins. An Exact rule is treated as a full-length match.
- If no rule matches, the Default Base Path rule is used.
The Default Base Path (path /) always exists and is always the fallthrough. You cannot have a redirect without it.
Worked example
Rules on a redirect for example.com:
- Default Base Path
/→https://newsite.com - Starts With
/blog→https://newsite.com/articles - Starts With
/blog/2024→https://newsite.com/archive/2024 - Exact Match
/about→https://newsite.com/company
How matches resolve:
/→ rule 1 (default fallthrough)./about→ rule 4 (Exact match wins)./blog→ rule 2./blog/post-1→ rule 2 (Starts With match)./blog/2024/highlights→ rule 3 (longer Starts With wins over rule 2)./careers→ rule 1 (no specific match).
Why longest match wins
Longest-match semantics are intuitive: a more specific rule is usually what you intend when it's available. This matches how HTTP path routing works in common frameworks (Rails, Django, Express, etc.) and avoids rule-order dependencies.
Query strings
Query strings are not part of the path match. To branch on query parameters, use a personalization audience with a Request Query Parameters rule and attach it to a Smart Target. The audience check happens after path selection.

