EdgeRules can be configured to redirect a client based on the User-Agent sent with the request. We will look at an example of this here.
The EdgeRules feature is available only on Enterprise plans.
Example: Redirecting by User-Agent
Some user agents (web browsers) act differently than others. In this example we will show you how to create a redirect if the end user is using a iPhone or Android smartphone.
Looking at the Rule
cURL example Before Rule
curl -A "Android" -I edgerules.86400.io/ua-test.html
HTTP/1.1 200 OK
[clipped]
Server: NetDNA-cache/2.2
X-Cache: HIT
Accept-Ranges: bytes
cURL example After Rule
curl -A "Android" -I edgerules.86400.io/ua-test.html
HTTP/1.1 301 Moved Permanently
Location: http://edgerules.86400.io/mobile
Date: Sat, 19 Jan 2013 01:11:29 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Server: NetDNA-cache/2.2
Regular Expression Visualization
Resulting Nginx Configuration Block
location = /ua-test.html {
if ($http_user_agent ~* (Android|iPhone)) {
rewrite ^ http://edgerules.86400.io/mobile permanent;
}
We hope this article was helpful and as always, If you have any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email!