URI rewrite with wildcard
Working on setting up an irule and have been using this post for reference.
Request will be coming in as https://site.domain.com/text1/text2/text3/wildcard/text4, where the wildcard can be any app name and the other values are constant.
Then we need to rewrite the uri to be /text5/text6/text7/wildcard/text4. We'll be keeping the "/wildcard/text4" part of the uri but the rest will be changing. So the request will look like https://site.domain.com/text5/text6/text7/wildcard/text4
Then send it to a different pool.
Have come up the following, though the skip_count was confusing me a bit. I assume I don't want any characters to be skipped when pulling in the wildcard value. I saw that regex is discouraged due to cpu, so not sure if there's a better way to accomplish this.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] matches_regex "(\/text1\/text2\/text3).*(\/text4)" } {
set filter [findstr [string tolower [HTTP::uri]] "/text1/text2/text3/" 0 "/text4"]
set newuri [string map "/text5/text6/text7/$filter/text4" [string tolower [HTTP::uri]]]
HTTP::uri $newuri
pool pool1
}
}
Thanks for any assistance.