reldar_76465
Jul 13, 2011Nimbostratus
redirect mobile devices
Hi,
I'm looking for a script that will enable us to redirect all traffic coming from mobile devices to a mobile site.
Many thanks for the help.
Roy
I'm looking for a script that will enable us to redirect all traffic coming from mobile devices to a mobile site.
Many thanks for the help.
Roy
Here's a recent post to start with:
http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1178780/showtab/groupforums/Default.aspx
Aaron
now I created the below iRule to redirect all mobile traffic coming to my site to another site.
the thing is that on that 'other site', i want to have the reversed iRule that would redirect back to the original site all traffic that is NOT a mobile.
I would appreciate some guidance as how to 'reverse' the below script by using 'not'. something like 'if any of the below does not exist - redirect to www....'
thanks
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"*ipad*" - {
HTTP::redirect "http://m.mysite.com/[HTTP::uri]"
return
}
}
}
As you can see in the link that Hoolio posted, there are quite a few User-Agents (and more are being added with each release of a new Web-Mobile capable device), so you are going to have to maintain a list one way or the other.
The list of non-mobile browser User-Agents (which is probably far more manageable) or a list of mobile User-Agents in order to fully tackle what you are trying.
I would suggest changing your iRule on the mobile Virtual Server to capture the non-mobile browser agents and redirect them to your non-mobile site and on your non-mobile site reverse the logic and say if you are not a non-mobile browser redirect to the mobile site. Then you should only have to keep track of one set of User-Agents.
You could also put a default action to log any unknown User-Agents when you want to see what the site is actually processing (and comment it out when not needed):
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"*ipad*" - {
log local0. "Device Access Attempt [HTTP::header User-Agent]"
HTTP::redirect "http://m.mysite.com/[HTTP::uri]"
return
}
}
}
(It is also worth noting that if people find out how you are filtering their traffic, it is possible to change the User-Agent of most devices to get around this type of filter).
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"*ipad*" { }
default {
HTTP::redirect "http://mysite.com/[HTTP::uri]"
}
}
}
Basically all you need to do is make the cascading list of fall-through logic end with something other than the redirect. It could be sending the request to a pool or simply doing nothing, as above. Then everything that doesn't match one of those cases, which are the mobile cases, will fall through to the redirect and get sent to your non mobile site.
Colin
All you mentioned is very true, but doing the opposite (create a script to 'allow' desktops, rather than redirect mobile) is more risky. I can live with the fact that mobile will go to the original site, but I can't afford desktops being redirected to the mobile site. Anyway, if you keep the main players in the list, there is 80% coverage which is good enough for me.
one question though - I tried Colin's suggestion and it didn't work for me. Did I miss anything? Do you need to add something to it?
Thanks again
This one will redirect for blackberry or ipad, and log the User-Agent any other devices.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"*ipad*" {
HTTP::redirect "http://m.mysite.com/[HTTP::uri]"
return
}
default { log local0. "Device Access Attempt [HTTP::header User-Agent]" }
}
}
You can remove the / in the redirect between the hostname and [HTTP::uri]:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"*ipad*" {
HTTP::redirect "http://m.mysite.com[HTTP::uri]"
}
default { log local0. "Device Access Attempt [HTTP::header User-Agent]" }
}
}
Also, you don't need the return in the switch statement as only one switch case will ever get executed.
Aaron
I like your suggestion of using a list of non-mobile browsers and the User-Agents. How would I accomplish that? What I change the agents you have to simply "*Mozilla*"- and "*IE*"- etc....
There are a few additional examples and a partial list in this post: (http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=15116)
The best way to get a list is to create a logging statement (log local0. "Device Access Attempt [HTTP::header User-Agent]").
This will put the User-Agent into your /var/log/ltm log and you can grep it with the iRule name to see what is being logged.
You could also go here, but this is quite a list: http://www.user-agents.org/
Keep in mind that if you use a datagroup list to split between Desktop Browser Traffic and Mobile Traffic, that either way you are going to have to maintain a list of one or the other and every time a new mobile device comes out you may need to update your list.
The entries you listed contain wildcards so that they will catch all Mozilla based browsers “*Mozilla*”, or all versions of Internet Explorer “*IE*”, but I would be careful using them since I know that there are mobile versions of IE, and perhaps Mozilla based browsers.
My web team would like to know if there is a way to redirect mobile devices. But when users have a mobile device and prefer the full site, have a link on our mobile site that takes them to the full page. I've tried this and it loops. Apple iPad would be an example.