Forum Discussion
Hans_Schneider2
Nimbostratus
Jul 10, 2007Rewriting /aaa to /bbb and assigning pool transparently
Hi All,
I have a virtual server set up that I wish to add an irule for.
Basically the start of the uri will be used to choose the actual context on the actual servers in the pools. ...
Jul 10, 2007
You are pretty darn close with your pseudo code. Unfortunately, there isn't a "HTTP::uri replace" command. The best way to do it is with the "string map" command. I'd go something like this
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"/aaa*" {
HTTP::uri [string map { /aaa /111 } [HTTP::uri]]
pool 111_pool
}
"/bbb*" {
HTTP::uri [string map { /bbb /222 } [HTTP::uri]]
pool 222_pool
}
"/ccc*" {
HTTP::uri [string map { /ccc /333 } [HTTP::uri]]
pool 333_pool
}
default {
HTTP::redirect "https://[HTTP::host]/aaa[HTTP::uri]"
}
}
}
I prefer a switch statement as it's usually cleaner to read, but feel free to do an if/elseif with the starts_with operator if you prefer.
The string map command will replace all occurrances (important to know if there are multiple occurrances of the first string) of the first string with the second string in the given value. So for the first case above, it will replace all occurrances of "/aaa" with "/111" in the value of [HTTP::uri] and will then return that value with is then assigned to the URI with the surrounding HTTP::uri command (brackets mean return the value, no brackets mean assign it).
As for modifying the returned traffic, you can build that logic into the iRule by interrogating the HTTP::payload in the HTTP_RESPONSE and HTTP_RESPONSE_DATA events. The SSN Scrubber example in the CodeShare shows how to do this:
http://devcentral.f5.com/Wiki/default.aspx/iRules/SocialSecurityNumberScrubbing.html
Click here
But, a far easier method would be to use the Stream profile (if you have it licensed). This thread talks about how to use the Stream profile
http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&forumid=5&postid=13504
Click here
Hope this helps!
-Joe
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