Forum Discussion
Greg_76561
Nimbostratus
Jan 28, 2011Route to different pools based on /content
Hello,
I'm new to iRules and trying to come up with a way to send traffic to different pools based on the /content in the url.
I have a secure site which the ssl certificate is ins...
hoolio
Cirrostratus
Jan 31, 2011Chris,
The string first command works nicely with this because you can skip the first forward slash and get the index of the second forward slash (after the /qa or /uat directory) using the "startIndex" parameter. But the string range commands you used have the same effect. But make sure you're checking for URIs starting with a forward slash in your switch statement (/uat and /qa). And you'll need a -glob flag on the switch statement.
Greg,
The HTML content that the server replies with won't have these /qa or /uat prefixes unless the servers have been configured to include them. You could try to insert them in all of the HTML, but it would get complicated trying to parse the HTML. If the initial request from the users contains the prefix, you could set a cookie to track that they're a UAT, QA or general user. You could check for that cookie if the URI doesn't match a UAT or QA URI.
Here's an untested example:
when HTTP_REQUEST {
Default to not setting a pool cookie
set pool_cookie ""
Check URI set to lower case with wildcard matching
switch -glob [string tolower [HTTP::uri]] {
"/uat*" {
pool uat_pool
HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end]
set pool_cookie uat
}
"/qa*" {
pool qa_pool
HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end]
set pool_cookie qa
}
default_pool {
Check if user has pool cookie
switch [HTTP::cookie pool_selector] {
"qa" {
pool qa_pool
}
"uat" {
pool uat_pool
}
default {
pool general_pool
}
}
}
}
}
when HTTP_RESPONSE {
Set a pool selector cookie if a UAT or QA pool as selected in request
if {$pool_cookie ne ""}{
HTTP::cookie insert name pool_selector value $pool_cookie
}
} Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
