Forum Discussion
irule to rewrite uri in http request and response
Hi Guys, really need to borrow your expertise. recently I ran into a request from our application team. they currently have an existing environment configured on LTM. They want to create a new pool on the F5 with new servers and be able to swap pools directly behind the LTM by using different uri. it's like below:
Existing URL: Existing pool: "pool1" new pool: "pool2"
when user calling , the traffic will be send to pool1 when developer calling , traffic will be sent to pool2
if it stops here, it's easy to be realized. however, the application team indicated that in both pool1 and pool2, all servers must be configured exactly same with path /review/test
that means if the http request is hitting the pool2 with /review2/test, it will get error. so I wrote an irule to rewrite the uri from /review/test to /review/test2 on F5 before send it to the backend pool. but now the problem is the http_reponse traffic. since the servers in pool2 is also configured by /review/test path. then when it's responding to the user, they http_response contains /review/test only. they when user try to click anything on the page, it will be send to pool1 by F5. I tried to use stream profile with irule to rewrite the http_response replacing all /review/test to be /review2/test but seems no effect at all.
anyother thing is that when I'm doing the rewrite on the http_response, I also need to check where the HTTP_reponse coming from, if it's actually coming for pool1, then I should not do rewrite becuz those are legit /review/test return traffic. I should only rewrite the reponse payload and http header on the traffic from pool2.
anyone has idea how to make this happen? I will try to attach my irule here for you guys to review as well.
- Marcus_Hong_Yu
Nimbostratus
here is the irule I tried, it seem the http_request rewrite works but the http_response part not taking effectWhen HTTP_REQUEST { if { [HTTP::uri] contains "/review2"} { HTTP::uri [string map {/review2 /review}[HTTP::uri]] } } When HTTP_RESPONSE { if {[class match [IP::server_addr] equails "review2_srcIP"} { HTTP:header replace Location [string map {/review /review2} [HTTP::header value Location]] STREAM::expression "@/wot@/wot2@" STREAM::enable } }
- JG
Cumulonimbus
Try this:
when HTTP_REQUEST { if { [string tolower [HTTP::path]] starts_with "/review2"} { HTTP::path [string map { "/review2" "/review" } [HTTP::path]] pool pool_2 } else { pool pool_1 } } when HTTP_RESPONSE { if { [class match [IP::server_addr] equals private_net] } { if { [HTTP::header exists "Location"] } { HTTP::header replace Location [string map { "/review/" "/review2/" } [HTTP::header Location]] } STREAM::expression {@/review/@/review2/@} STREAM::enable } else { STREAM::disable } } when STREAM_MATCHED { STREAM::replace log local0. "String matched and replaced." }
.
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