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...
hooleylist
Jan 16, 2012Cirrostratus
You should be able to set a cookie to track whether the client has opted for either the full site or mobile site based on requests to www.site.com/?mobile=false or a URI which selects the mobile site. Here's a rough idea of what I'm thinking:
Main (non-mobile) site iRule
when HTTP_REQUEST {
Use full site if user has main (non-mobile) site cookie
if {[HTTP::cookie site] eq "main"}{
Do not redirect clients who have manually opted for the main site
} else {
User has not manually opted for the main site
Check if the client is a mobile
if {[class match -- [string tolower [HTTP::header "User-Agent"]] contains mobile_class]}{
if {[class match -- [string tolower [HTTP::uri]] contains specific_uri_class]} {
set mobile_opt_uri [class match -value [string tolower [HTTP::uri]] contains specific_uri_class]
HTTP::redirect "http://m.site.com$mobile_opt_uri"
} else {
HTTP::redirect "http://m.site.com/"
}
}
}
}
Mobile site iRule
when HTTP_REQUEST {
Check if request is to a URI which indicates a mobile user wanting to use the main site
if {[HTTP::query] eq "mobile=false"}{
Redirect to main site with a cookie to track the user wants to stay on the main site
HTTP::respond 302 Location "http://www.site.com/" Set-Cookie "Site=main; domain=.site.com"; path="/";"
}
}
Aaron
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