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.
I.e. in pseudo code, which I have been trying multiple variations of:
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/aaa" } {
HTTP::uri replace "/aaa" "/111"
pool 111_pool
}
elseif { [HTTP::uri] starts_with "bbb" } {
HTTP::uri replace "/bbb" "/222"
pool 222_pool
}
elseif { [HTTP::uri] starts_with "ccc" } {
HTTP::uri replace "/ccc" "/333"
pool 333_pool
}
else {
This is just here to catch the rest
HTTP::redirect "https://[HTTP::host]/aaa[HTTP::uri]"
}
}
So that the LTMs will send the request to one of the servers in the pools (they're set up fine btw) for example http://10.10.10.10/111/blah.html where /111 is set up on apache as a context.
Is it possible also so that I could do something for the returning traffic so that the end user doesn't notice the uri translation?
Thank you for your patience, and time.
Best regards,
- 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]" } } }
http://devcentral.f5.com/Wiki/default.aspx/iRules/SocialSecurityNumberScrubbing.html
http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&forumid=5&postid=13504
- Hans_Schneider2
Nimbostratus
Excelent stuff man! Thanks a lot! I appreciate your help. - Oh, I thought you were talking about replacing all embedded links from the /aaa to /111. Per the HTTP protocol, the HTTP response does not return the URI back to the browser so there is no way on the response for you to tell the browser that you changed the URI on the backend. If you want the browser address bar to change, you will have to issue a full redirect back to the browser in the HTTP_REQUEST event instead of just modifying the URI before it gets to the backend server. This way the browsers address bar will be changed with your updated urls.
- Brian_Moore_603
Nimbostratus
I have a similar issue with a "One IP to many pools" type setup, However my front VIP is a redirect to port 443 so I am trying to do the iRule to pool after the redirect and it's not working. How can I keep the traffic redirected to 443 for a single IP to multiple pools, below is an example of my setup.... - hoolio
Cirrostratus
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