Agent-readable docs index: /docs/llms.txt. Full docs in one file: /docs/llms-full.txt. Download /docs/docs.zip to grep all markdown files locally.

Device & Geo-Targeting Smart Routing

Smart routing turns one short URL into an intelligent traffic distributor — routing visitors to the right destination based on device type or geographic region with sub-10ms edge evaluation.
No client-side JavaScript. No redirect flicker. Rules execute directly at Cloudflare's global edge network before the response reaches the browser.

When to Use Smart Routing

Universal App Link
One link sends iOS users to the App Store, Android users to Google Play, and desktop users to your website.
Regional Content
Redirect visitors from different countries to localized landing pages, region-specific pricing, or language-appropriate content.
Platform-Specific Promotions
Run separate campaigns per OS — different promo codes, CTAs, or incentives per device type.

Configuring Device Rules in the Console

    In the Links view, click Create Link or hover over an existing link and click Edit.

    Scroll to Smart Routing

    Locate the Smart Device Routing section below the main destination URL field.

    Set Platform Destinations

    Enter the Apple App Store URL:
    https://apps.apple.com/app/id123456789
    Matches any User-Agent containing iPhone, iPad, iPod, or CriOS (Chrome on iOS).
    Click Save Link. Rules are deployed globally within seconds.

Configuring Geographic & Regional Routing (Geo-Targeting)

Shaf leverages Cloudflare's Anycast edge network to inspect the visitor's geographic location (cf.country) at the nearest data center (330+ locations globally) with zero database roundtrips.
Country-Level Targeting
Route visitors based on 2-letter ISO 3166-1 alpha-2 country codes (e.g. US, GB, DE, JP, FR, BR).
Localized Pricing & Currencies
Send North American visitors to USD pricing (/pricing?cur=usd) and European visitors to EUR pricing (/pricing?cur=eur).
Compliance & Data Privacy
Direct European Union visitors to dedicated GDPR-compliant consent workflows and localized legal notices.

Setting Up Geo Rules via Console

    Select Target Region

    In the Smart Routing card, click Add Geographic Rule. Select the target country from the dropdown or enter its standard 2-letter ISO code (e.g., DE for Germany, JP for Japan, GB for United Kingdom).

    Provide Regional Destination URL

    Enter the destination specifically configured for that regional audience:
    https://yourbrand.com/de/sommer-angebot

    Configure Global Fallback

    Visitors outside of your explicitly defined country rules automatically route to your primary Default Destination URL.

    Deploy to Edge

    Click Save Link. The rule compiles immediately into Cloudflare KV edge storage across all global PoPs.

How Edge Evaluation Works

When a visitor clicks your link, Shaf evaluates rules in the following priority order directly at the edge:
  1. Geographic Origin Match (cf.country header vs. active ISO country rules)
  2. Device / OS Match (User-Agent header vs. iOS/Android rules)
  3. Primary Default URL (Fallback destination)
Rendering diagram...
SignalMatched Header ValuesDestination
iOSiPhone, iPad, iPod, CriOSApple App Store
AndroidAndroidGoogle Play Store
DefaultEverything elsePrimary destination URL
Privacy-first: User-Agent inspection happens at the edge. No visitor data is stored, logged, or transmitted to third parties for routing purposes.

Troubleshooting

My iOS users are still hitting the default destination
Verify the Apple App Store URL is correctly formatted. The App Store URL must begin with https://apps.apple.com/. Also confirm you clicked Save Link after adding the routing rule.
Desktop users are being matched as Android
This is rare but can happen with some user agent strings on Linux. The Android match checks for the literal string Android in the user agent — Linux desktops typically return strings like X11; Linux x86_64. If you encounter consistent false positives, file a support ticket with the affected user agent string.
How do I test routing without an iOS or Android device?
Use a browser extension that spoofs user agents (e.g. User-Agent Switcher for Chrome) or use cURL with a custom header:
# Simulate iPhone curl -A "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X)" -I https://link.yourbrand.com/app # Simulate Android curl -A "Mozilla/5.0 (Linux; Android 13; Pixel 7)" -I https://link.yourbrand.com/app