Forum Discussion
Redirects to a mobile site not being completed by iRule
Hi I wrote this irule, the redirect stops at http://desautels.mobilize.com and does not actually redirect to the full path desired, does anyone have a suggestion? I am using Chrome but with a user-agent switcher for testing.
Regards
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.mcgill.ca/desautels/programs/isp" } {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*blackberry*" -
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5 *"-
"*Android*" -
"*Windows Phone OS 7*" -
"*Windows Phone OS 8*"-
}
{
HTTP::redirect "http://desautels.mobilizeme.com/undergraduate_programs/isp"
}
}
}
9 Replies
- What_Lies_Bene1
Cirrostratus
Your if is wrong, you really need a space after the Mozilla line, before the hyphen and the redirect line is in the wrong place. Here's my rewrite;when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals "www.mcgill.ca") && ([string tolower [HTTP::uri]] equals "/desautels/programs/isp")) } { switch -glob [string tolower [HTTP::header User-Agent]] { "*blackberry*" - "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5*" - "*Android*" - "*Windows Phone OS*" { HTTP::redirect "http://desautels.mobilizeme.com/undergraduate_programs/isp" } } } } - What_Lies_Bene1
Cirrostratus
Personally I'd use a Data Group and do it like this;Create a Data Group (called user-agent-dg below) with just strings containing the user agent strings you wish to match when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals "www.mcgill.ca") && ([string tolower [HTTP::uri]] equals "/desautels/programs/isp")) } { if { [class match [string tolower [HTTP::header User-Agent]] equals user-agent-dg ] } { HTTP::redirect "http://m.example.com" } Stop processing the iRule for this event here return } } - What_Lies_Bene1
Cirrostratus
I'd also suggest you do a quick search here on DC for some better lists of possible mobile User-Agent strings. - chungyu_16122
Altostratus
Hey thanks for the quick response, I will look at both examples and try them out. Happy New Year too everyone out there.
Chung
- chungyu_16122
Altostratus
Hi I just tried this format, I am assuming the iRule should be using the & rather than ;amp However, i just get a page not found, rather than a redirect. when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals "www.mcgill.ca") & ([string tolower [HTTP::uri]] equals "/desautels/programs/isp")) } { switch -glob [string tolower [HTTP::header User-Agent]] { "*blackberry*" - "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5*" - "*Android*" - "*Windows Phone OS*" { HTTP::redirect "http://desautels.mobilizeme.com/undergraduate_programs/isp" } } } } - What_Lies_Bene1
Cirrostratus
It's two &'s: &&. Any errors in the ltm log? - nitass
Employee
can you add some log command in the irule? traffic might not reach the HTTP::redirec command. - chungyu_16122
Altostratus
Thanks, that seems to get everything working properly, the only problem i still have is getting the right user-agent strings. When i use chrome as a Blackberry Bold, things are ok, but my iPHone or Android setting in Chrome don't seem to work. I tried looking up iphone user-agent string and plugged in *Apple-iPhone* but that does not seem to work at all. Chung - Michael_Yates
Nimbostratus
Hi chungyu,
I agree with Nitass. You should put a logging statement in your iRule and see what User-Agents are being processed.
log local0. "[HTTP::header User-Agent] Device Detected"
For Testing you can use a Mozilla Plugin User-Agent-Switcher.
A good place to get a list of User-Agents can be found here UserAgentString.com
Hope this helps.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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