F5 Technology Blog

Wednesday, February 19, 2014

Mobile Detection iRule

Use case:
Redirect www.mydomain.com (desktop website) to m.mydomain.com (mobile website)

1) Create a data group
Local Traffic > iRules > Data Group List > Create
Name: mobile-user-agents
Type: String

Add Records
Example:
String iphone
Value: (leave this empty)

Here is the list of mobile user agents I used.

avantgo
bada
bb
blackberry
blazer
bolt
compal
elaine
fennec
gobrowser
hiptop
iemobile
iphone
iris
kindle
lge
maemo
mib
midp
minimo
mmp
netfront
palm
phone
semc-browser
skyfire
symbian
teashark
teleca
uzardvodafone
wap

2) Create an iRule
Local Traffic > iRules > iRules List > Create
Name: mobile-rule-v1
Definition:

when HTTP_REQUEST {
 set useragent [string tolower [HTTP::header User-Agent]]
 set mobilehost "m.mydomain.com"
 set uri [HTTP::uri]
 set ismobile false

 if { [matchclass $useragent contains mobile-user-agents ] } {
  set ismobile true
 }
 elseif { $useragent contains "android" } {
  if { $useragent contains "mobile" } {
   set ismobile true
  }
 }

 if { $ismobile } {
   HTTP::redirect "http://$mobilehost$uri"
   # Do any other logic here
 }
}

3) Add the iRule to the virtual server

posted by Jayanthi Krishnamurthy @ 1:02 PM   0 Comments

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

Newer›  ‹Older

About Me

Name: Jayanthi Krishnamurthy

View my complete profile

Posts

  • Mobile Detection iRule

Older Posts Newer Posts

Archives

Subscribe to
Posts [Atom]