Skip to main content

User Agent Filtering Example

With Traffic Policy, you can check a request's User-Agent header to deliver tailored content to users based on their browser and device, or to customize responses for SEO crawlers and bots.

This rule delivers tailored content to Microsoft Edge users by examining the User-Agent header for the case-insensitive string (?i)edg/ succeeded by digits \d. To see how this works in practice, explore the following regex101 demonstration.

You can use one of the following snippets:

Policy

Loading…

Agent Config

Loading…
tip

To ensure correct decoding from YAML/JSON, it's necessary to properly escape the \d sequence. In YAML, if your string is not enclosed in quotes, use a single escape: \\d. However, when your string is wrapped in quotes, either in YAML or JSON, you need to double-escape: \\\\d for accurate decoding.