Announcing our new API documentation!
Check it out here

Redirect path selection algorithm

How SiteDetour picks which path rule to apply to an incoming request, and why the longest match wins.

On this page:

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:// or https://): 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:

  1. Exact Match — the request path must equal the rule path character-for-character.
  2. Starts With — the request path must begin with the rule path.

Selection rules

SiteDetour walks every rule in the redirect:

  1. For Exact rules, it checks for a precise string equality. If an Exact rule matches, it's a candidate.
  2. 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.
  3. Among candidates, the longest match wins. An Exact rule is treated as a full-length match.
  4. 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:

  1. Default Base Path /https://newsite.com
  2. Starts With /bloghttps://newsite.com/articles
  3. Starts With /blog/2024https://newsite.com/archive/2024
  4. Exact Match /abouthttps://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.

Next steps