Forum Discussion
cokeefe28_17139
Jan 16, 2012Nimbostratus
Mobile Device Detection with logic
All, I seem to be spinning my wheels here and I am not sure why. I want to do the following: 1. Detect if a user is coming from a mobile device (for simplicity, we will say o...
cokeefe28_17139
Jan 18, 2012Nimbostratus
I have gotten the following to work....a little of Aaron and a little of mine, but I think that Nitass is right....I may not be able to track this with a cookie since most mobile devices don't use cookies. Src IP will not work because there are the cases of NAT. I think that the only way that I can get this to work is by only executing this on the front login page (say index.htm) and have all the other pages reference home.htm. That way I can put something in there that says If not HTTP::uri /index.htm....exit. Thoughts? Here is the iRule.
when HTTP_REQUEST {
Set a varible to the URI minus the trailing slash (i.e. /TEST not /TEST/)
set uri [string trimright [HTTP::uri] "/" ]
set mobile_site "http://m.site.com"
if {[HTTP::cookie site] eq "main"}{
} else {
Case Select if you are a using a mobile phone (Blackberry, Windows Mobile, Android, iPhone, iPad)
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"*wp7*" -
"*androi*" -
"*iphone*" -
"*ipad*" {
if {[class match -- [string tolower $uri] contains mobile_phone_optimized_uri]}{
set mobile_opt_uri [class search -value mobile_phone_optimized_uri eq [string tolower $uri]]
HTTP::redirect $mobile_site/$mobile_opt_uri
event disable
} else {
HTTP::redirect $mobile_site
}
}
default {
}
}
}
Are you using WAP?
if { [string tolower [HTTP::header Accept]] contains "vnd.wap.wml" } {
HTTP::redirect "http://m.site.com"
return
}
if { [HTTP::header exists "MSISDN"] } {
HTTP::redirect "http://m.site.com[HTTP::uri]"
return
}
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects