Forum Discussion
JWhitesPro_1928
Cirrostratus
Oct 03, 2016Best way to rewrite and choose different pool at same time
What would be the best method to achieve the following:
If incoming url starts with "/test" replace /test with just "/" and choose pool "test"
I've done some of my other pool selection wit...
VernonWells
Employee
Oct 03, 2016when HTTP_REQUEST {
if { [HTTP::path] equals "/test" } {
HTTP::path "/"
pool test
}
}
This will match exactly (and only) /test and nothing else.
Josh_Jacobson_4
Altostratus
Oct 04, 2016You can use [HTTP::uri] to preserve any GET vars (if you don't care about GET vars [HTTP::path] is fine too of course). Here's one way to strip the first segment of the path and send the rest on. I broke it out into two statements in case that's easier to read, and there's a one-liner version of it at the end too.
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/test/" } {
This will find the position of the second slash (starts searching at position 1; first slash is position 0)
set slashpos [string first / [HTTP::uri] 1]
Substring from the position of the second slash through the end of the URI
set newuri [substr [HTTP::uri] $slashpos]
Here's the one-liner to accomplish the same thing (it was just easier to comment as two statements):
set newuri [substr [HTTP::uri] [string first / [HTTP::uri] 1]]
log local0. "New URI: $newuri"
HTTP::uri $newuri
pool test
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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