Forum Discussion

soymanue's avatar
soymanue
Icon for Nimbostratus rankNimbostratus
Jun 21, 2013

switch wildcards

Hello

 

I have an iRule that makes two redirections depending on User Agent.

 

It's something like this:

 

switch -glob [string tolower [HTTP::header User-Agent]] {

 

"*android*" -

 

"*windows phone*" -

 

"*iphone*" -

 

"*blackberry*" -

 

"*bb10*" -

 

"*symbianos*" -

 

"*webos*" -

 

"*windows ce*" -

 

"*windows phone os 7*" {

 

HTTP::redirect https://www.mysite.com/mobile

 

}

 

default {

 

HTTP::redirect "https://www.mysite.com/default"

 

}

 

}

 

I want to split Android on two cases:

 

- Smartphone: Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03O) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19

 

- Tablet: Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03S) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19

 

 

So, for Android smartphones, User-Agent contains both "Android" and "Mobile"

 

I know it can be done with an if or switch inside the previous switch. But can it be done with a single check?

 

Would this switch statement work? -> "*android*mobile*"

 

If not, I suppose I should make it with a regular expression. shouldn't I? How would it look like?

 

 

Thanks