DocSmooTH_23746
Apr 07, 2008Nimbostratus
regexp match HTTP::host to choose pool
I couldn't find anything in this forum searching for "regexp http::host" or "regexp matchclass" that fit my problem, but we did get the idea from one of Joe's blog posts.
We have a bunch of pools that are all essentially the same, from the pool setup, except for the member list and the content on those members. The nodes are the same, just not the backend service ports or members. What we want is the user to be able to hit a hostname, and be sent to the appropriate pool, like:
http://web-dev --> pool_web-dev (which is http://node:8081)
http://web-tst --> pool_web-tst (http://node:8082)
http://web-stg --> pool_web-stg (http://node:8083)
So we have a class defined as follows:
class class_web-sids {
"web-dev"
"web-tst"
"web-stg"
}
and an iRule:
when HTTP_REQUEST {
regexp {^([\w-]+)(\.)*} [HTTP::host] sid
if {"" ne $sid } {
if { [matchclass $sid equals $::class_web-sids] > 0 } {
pool pool_$sid
}
}
}
If the user hits "http://web-dev", they get passed to the right pool. The problem is if they hit "http://web-dev.domain.com" they get the default pool. With the regexp the way it's written, it should be stopping at the first "." and just giving me the pool matched to the 2nd level of the FQDN, right? What do I need to change to get either "http://web-dev" or "http://web-dev.domain.com" to match to "pool_web-dev" ?
Thanks!
Rob