Forum Discussion
WAP and mobile irule question
The goal is if a mobile phone with it's user_agent included in a Data Class to direct it to one site and if it isn't in the Data Class then redirect somewhere else.
I think my logic might be off. Can anyone take a look?
when HTTP_REQUEST {
set wap "https://onesite.com "
set normal "http://www.google.com"
if {[class match [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class]}{
HTTP::redirect $wap
log local0. "WAP"
} elseif { not ([class match [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class])}{
Redirect to the normal
HTTP::redirect $normal
log local0. "No WAP"
} else {
}
}
I am using a Nokia simulator to test and then using just a normal browser to test non-list WAP phones.
Thanks for any assistance.
7 Replies
- Mohamed_Lrhazi
Altocumulus
The logic looks off...
1: if condition1 do-one
2: elseif not condition1 do-two
3: else do-three
You might want simply:
1: if condition1 do-one
2: else do-two - What_Lies_Bene1
Cirrostratus
This should achieve the desired result;when HTTP_REQUEST { set wap "https://onesite.com " set normal "http://www.google.com" if { [class match [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class] } { HTTP::redirect $wap log local0. "WAP" } else { Redirect to the normal HTTP::redirect $normal log local0. "No WAP" } } - pmaubo2_55685
Nimbostratus
The problem I seem to run into is it sends it to the wap redirect no matter if it's one of the codes in my data class or not and even if I just use a browser so it never seems to get to the 2nd redirect via the else. - What_Lies_Bene1
Cirrostratus
If that's the case, even with my suggested modifications, I'd suggest you change the log statements to also log the User-Agent so you have an idea what's being presented.
Is everything in your data group lower case? It needs to be!
- pmaubo2_55685
Nimbostratus
Below is the output. The 1st one shows the redirect via just a browser, the one below shows correctly that it saw the nokia keyword in the data class. For some reason I must be missing some type of end statement or event disable, tried that but no dic.
Oct 30 15:56:18 local/tmm info tmm[4899]: Rule mobile_detect_uri_irule : Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)
Oct 30 15:56:18 local/tmm info tmm[4899]: Rule mobile_detect_uri_irule : WAP Redirection
The below is using a nokia simulator
Oct 30 15:56:47 local/tmm info tmm[4899]: Rule mobile_detect_uri_irule : Nokia5100/2.0 Profile/MIDP-1.0 Configuration/CLDC-1.0
Oct 30 15:56:47 local/tmm info tmm[4899]: Rule mobile_detect_uri_irule : WAP Redirection - What_Lies_Bene1
Cirrostratus
OK and that's using my iRule?
Is everything in your data group lower case? This is important! - nitass
Employee
i think you have to add additional condition in if clause, such as host header or uri, to prevent redirection loop.
e.g.when HTTP_REQUEST { if { [HTTP::host] equals "onesite.com" } { if { not [class match -- [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class] }{ HTTP::redirect "http://www.google.com" } } else { if { [class match -- [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class] }{ HTTP::redirect "https://onesite.com" } } }
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