Forum Discussion
HTTP::header User-Agent question
I have an irule for we are setting up for featured mobile phones and smart phones.
1 data class list many different codes, for example nokia, the non-smartphones.
The other data class just lists smartphones we support.
The goal is to detect a smartphone and direct it to one site and if it's a featured phone it detects it and directs it.
The problem is, if I use just a PC browser it always seems to take the featured phone path.
If it's just a standard browser on a pc, is there a way to force it to use it.
Seems like the HTTP::header User-Agent is looking into my data class with all the codes and then uses the wap data class regardless. I would think if I am using a not in my "if" it should use the set of normal?
All
Below is the irule
when HTTP_REQUEST {
set wap https://wapsite.com/uri
set normal https://normal.com/uri
set smart https://smartphonesite.com/uri
if { [HTTP::host] equals "https://mysite..com" } {
if { not [class match -- [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class] }{
log local0. "Normal web site"
HTTP::redirect $normal
}
} else {
if { [class match -- [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class] }{
log local0. "wap phone"
HTTP::redirect $wap
if {[class match [string tolower [HTTP::header User-Agent]] contains mobile_device_providers]}{
log local0. "smart phone"
HTTP::redirect $smart
event disable
do nothing
} else {
}
}
}
}
4 Replies
- nathe
Cirrocumulus
Hey, - nathe
Cirrocumulus
I'd also take a closer look at your if else clauses, looks like you'd have better luck with if/elseif/else combination. - What_Lies_Bene1
Cirrostratus
Try this;when HTTP_REQUEST { set wap https://wapsite.com/uri set normal https://normal.com/uri set smart https://smartphonesite.com/uri if { [HTTP::host] equals "https://mysite..com" } { if { [class match -- [string tolower [HTTP::header User-Agent]] contains user_agent_tokens_class] }{ log local0. "wap phone" HTTP::redirect $wap return } elseif {[class match [string tolower [HTTP::header User-Agent]] contains mobile_device_providers] } { log local0. "smart phone" HTTP::redirect $smart return } else { log local0. "Normal web site" HTTP::redirect $normal } } }
- nitass
Employee
as nathan mentioned, i just removed "https://" from Steve's irule. additionally, since you do string tolower twice, you had better save it to variable and re-use it.when HTTP_REQUEST { set wap "https://wapsite.com/uri" set normal "https://normal.com/uri" set smart "https://smartphonesite.com/uri" if { [HTTP::host] equals "mysite.com" } { set user_agent [string tolower [HTTP::header User-Agent]] if { [class match -- $user_agent contains user_agent_tokens_class] } { log local0. "wap phone" HTTP::redirect $wap } elseif { [class match -- $user_agent contains mobile_device_providers] } { log local0. "smart phone" HTTP::redirect $smart } else { log local0. "Normal web site" HTTP::redirect $normal } } }
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