I am trying to setup an irule such that traffic based on certain URL’s is directed towards the appropriate virtual servers. Essentialy we have mutliple URL’s " siteA.domain.com" , “siteB.domain.com”, “siteC.domain.com” and so on. What i want to do when the traffic comes in is that based on the incoming URL, i want the traffic to be sent to the VS defined for that site. I have a conceptual idea but when i put the rule in i get the error " command not valid in current scope"
I’m not sure if you can redirect to multiple virtual servers because the irule you are using it in one virtual server.
You can configure multiple pools and redirect to those pools based on the URL. Does that serves your purpose? I can help you creating an irule for that.
Otherwise you might need to create a wildcard wideip in GTM and create a DNS irule.
That will help. but here’s the thing. On the virtual servers for each of those SIte’s i also have a redirect to a specific login URI. Can you redirect to a pool and issue the appropriate redirect as part of the same iRUle ?
From your initial description, it doesn’t seem like you are sharing a single virtual server with multiple pools. It looked like a virtual server which redirects to other virtual servers. So, if that is the cause, the default pool (if one is set) for each of the virtual servers should serve the request to appropriate pools.
Actually i do want to use a single virtual server to redirect to other pools and at the same time perform the redirect to the appropriate URL once the pool is selected. Currently the way these are setup is a single VS for each site.
The rule i was going to use for pool selection is as below. Is it possible to do the redirect within this rule.
when HTTP_REQUEST { if {[HTTP::uri] contains “siteA.domain.com” } { log local0. “SiteA Access” pool vs_SiteA_prod_pool_pool } elseif {[HTTP::uri] contains “SiteB.domain.com” } { log local0. “SiteB Access” pool vs_SiteB_prod_pool } elseif {[HTTP::uri] contains “SiteC.domain.com” } { log local0. “SiteC Access” pool vs_kronos_prod_pool } elseif {[HTTP::uri] contains “SiteD.domain.com” } { log local0. “SiteD Access” pool vs_SiteD_prod_pool } else { log local0. “SiteA” pool vs_SiteA_prod_pool } } }
Without fully understanding 100% what it is you are trying to do still (because URL redirection is independent of the actual pool selection). Here is a modified (very crude) example of what you can do with your iRule above:
when HTTP_REQUEST {
if {[HTTP::uri] contains "siteA.domain.com" } {
log local0. "SiteA Access"
pool vs_SiteA_prod_pool_pool
if {[HTTP::uri] == "" || [HTTP::uri] == "/"} {HTTP::redirect "https://[HTTP::host]/TC/welcomeA.msv"}
} elseif {[HTTP::uri] contains "SiteB.domain.com" } {
log local0. "SiteB Access"
pool vs_SiteB_prod_pool
if {[HTTP::uri] == "" || [HTTP::uri] == "/"} {HTTP::redirect "https://[HTTP::host]/TC/welcomeB.msv"}
} elseif {[HTTP::uri] contains "SiteC.domain.com" } {
log local0. "SiteC Access"
pool vs_kronos_prod_pool
if {[HTTP::uri] == "" || [HTTP::uri] == "/"} {HTTP::redirect "https://[HTTP::host]/TC/welcomeC.msv"}
} elseif {[HTTP::uri] contains "SiteD.domain.com" } {
log local0. "SiteD Access"
pool vs_SiteD_prod_pool
if {[HTTP::uri] == "" || [HTTP::uri] == "/"} {HTTP::redirect "https://[HTTP::host]/TC/welcomeD.msv"}
} else {
log local0. "SiteA"
pool vs_SiteA_prod_pool
}
}
I personally would use the switch statement for this.
It looks from your original post that you are simply trying to make a pool selection based on the incoming Host header. For more details on the Host header, I encourage you to read the “Elaboration” section of this iRule recipe:
command selects a BIG-IP Virtual Server by name. That’s almost certainly not what you want (though it could be, if you had differing profiles attached to various Virtual Servers; but in that case, it usually makes more sense to map the DNS hostnames to differing IPs, one per Virtual Server). Again, assuming that you wish to select a BIG-IP Pool based on the incoming Host header value:
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"www.abc.com" {
pool abc_com
}
"www.def.com" {
pool def_com
}
"www.alpha.com" -
"www.beta.com" {
pool alphabet
}
}
}
To understand the dash case, see the Elaboration section of “Analysis” section of this recipe: