Forum Discussion
IRULE for HTTP string manipulation
I need help with creating a rule that will look for a key word and then redirect to a different VIP with the rest of the HTTP string intact.
For example,
Header comes with http://www.f5.com/abc/TRIGGER/whatever/whatever.
If the URI has the word TRIGGER
then replace the URL to
http://new.f5.com/abc/TRIGGER/whatever/whatever
Thanks in advance
5 Replies
- Richard__HarlanHistoric F5 Account
I would look at the string command contains.
https://devcentral.f5.com/wiki/iRules.contains.ashx
when HTTP_REQUEST { if {[HTTP::uri] contains "TRIGGER" } { HTTP::redirect "http://new.f5.com/abc/TRIGGER/whatever/whatever" } }You could also look at running HTTP::uri through string tolower to catch up and lower cases requests.
- fhlostonp_19913
Nimbostratus
Hi Richard, Thanks for the quick reply. The contains will work to identify the string that has TRIGGER in it, but the redirect will need the original string. So I won't know what the whatever/whatever is.
So if the original string is http://www.f5.com/abc/TRIGGER/calendar/render?tab=ncmain_7
then the redirect should be http://new.f5.com/TRIGGER/calendar/render?tab=ncmain_7
- Richard__HarlanHistoric F5 Accountthen all you have to do is update the HTTP::rediret "http://new.f5.com/TRIGGER/calendar/render?tab=ncmain_7"
- nitass
Employee
in case you want to make it a bit more dynamic.
by the way, i think fragment identifier part (starting with hashmark) is not sent to bigip.
Fragment identifier
http://en.wikipedia.org/wiki/Fragment_identifierconfiguration [root@ve11c:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when RULE_INIT { set static::removal "/abc/" set static::hostname "www.f5.com" set static::newhostname "new.f5.com" } when HTTP_REQUEST { if { [HTTP::host] eq $static::hostname } { HTTP::redirect "http://${static::newhostname}[string map [list $static::removal "/"] [HTTP::uri]]" } } } test [root@ve11c:Active:In Sync] config curl -I http://www.f5.com/abc/TRIGGER/whatever/whatever HTTP/1.0 302 Found Location: http://new.f5.com/TRIGGER/whatever/whatever Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve11c:Active:In Sync] config curl -I http://www.f5.com/abc/TRIGGER/calendar/render?tab=ncmain_7 HTTP/1.0 302 Found Location: http://new.f5.com/TRIGGER/calendar/render?tab=ncmain_7 Server: BigIP Connection: Keep-Alive Content-Length: 0 - fhlostonp_19913
Nimbostratus
Thanks for the reply. Yes I need it more dynamic. The examples I used are not clear. Sorry about that.
Original string http://www.f5.com/abc/TRIGGER/doc/1234
Redirect string http://new.f5.com/abc/TRIGGER/doc/1234
Using the suggestions above, I came up with the following rule. I will try and test.
when RULE_INIT { set static::newhostname "new.f5.com" } when HTTP_REQUEST { if { [HTTP::uri] contains "TRIGGER" }{ HTTP::redirect "http://${static::newhostname}[HTTP::uri]]" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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