Issue with iRule to choose mobile user agent for specific URI and multiple pool selection
Dear friends,
I need to ask for your help because I have break my head since the last week to fix an issue designing an iRule, I have tried several ways but it just works partially. I need to design an iRule that chooses users with mobile devices and load balance their requests to specific application pools matching the URI. For desktop users it must be the same, this must be in the virtual server in this example is . I have designed almost 10 different iRules I have tried in several ways and the iRules which are closer to my target are these:
I designed the first iRule in this way:when HTTP_REQUEST {
if { [class match [HTTP::header User-Agent] contains "mobile_class"] } {
When I try to access with a mobile device, it doesn't works, it seems it doesn't match with any user agent, then I receive a connection reset, because the options doesn't match with any member of the datagroup mobile_classswitch -glob [HTTP::host] {
"example.com" {
HTTP::redirect "; }
"; {
if { [HTTP::uri] equals "/" } {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
HTTP::redirect "www.example.com/ctsMobilePublic/index.jsp"
} elseif { [class match [HTTP::uri] starts_with "ctsmobile_class"] } {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
pool Pool-CTSM
} elseif { [class match [HTTP::uri] starts_with "regmobile_class"] } {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
pool Pool-CTSN
}
}
}
`
This else happen when the user agent doesn't belong to the datagroup list, this is for desktop users
} else {
`switch -glob [HTTP::host] {
"example.com" {
HTTP::redirect "www.example.com/servlet/example/inicio"
`
Here in this case, when you write the URL: example.com/ it redirects to [www.example.com/servlet/example/inicio/www.example.com/servlet/example/inicio](//www.example.com/servlet/example/inicio/www.example.com/servlet/example/inicio)
` }
"www.example.com" {
`
Here in this if, when you write the URL: [www.example.com/](//www.example.com/) it redirects to [www.example.com/servlet/example/inicio/www.example.com/servlet/example/inicio](//www.example.com/servlet/example/inicio/www.example.com/servlet/example/inicio)
` if { [HTTP::uri] equals "/" } {
HTTP::redirect "www.example.com/servlet/example/inicio"
} elseif { [class match [HTTP::uri] starts_with "SSO_class"] } {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
pool Pool-SSOSERVICIOS
} elseif { [class match [HTTP::uri] starts_with "CTSN_class"] } {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
pool Pool-CTSN
`
The main page URI /servlet/example/inicio must match with this class SRVLT_class
` } elseif { [class match [HTTP::uri] starts_with "SRVLT_class"] } {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
SSL::disable serverside
pool Pool-SRVLT
}
}
}
} }
I had to cut the iRule because it was very long and I had not enough space here, but, is just long because it has several elseif for each URI that matches with pool. With less cases but the logical is the same, for desktop users now is working fine except when I use the redirects for example.com and , because it makes something like a loop. But where it have become very complex is when I try to separate by mobile devices. By the way, the data group list mobile_class string type contains: ipad, iphone, android, windows phone, windows ce,etc
Can somebody help me please, I would appreciate a lot any suggestion Thanks a lot Ivan