Forum Discussion
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.
- cjunior
Nacreous
Hello,
Is that URI a fixed one with one wildcard piece?
If so, I would do this way:
when HTTP_REQUEST { # Checks whether the path starts with /text1/text2/text3 and ends with /text4 if { [string match -nocase {/text1/text2/text3/*/text4} [HTTP::path]] } { # Put /text5/text6/text7, append original URI from 18 char to end (Skip the starts length from /text1/text2/text3) HTTP::uri "/text5/text6/text7[string range [HTTP::uri] 18 end]" pool pool1 } }
Regards
- tfs128
Nimbostratus
Correct, only the wildcard can vary. It will always come in starting with /text1/text2/text3 which I'll need to change into /text5/text6/text7. The /wildcard/text4 will always end the URI.
Recent Discussions
Related Content
* 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