Forum Discussion
Brandon_High_10
Nimbostratus
Nov 17, 2004HTTP request rewriting
I want to use the BigIP to do something equivalent to apache's:
ProxyPass http://search.foo.com
ProxyPassReverse http://search.foo.com
Setting the HTTP::uri works in the HTTP_REQUEST handler. When search.foo.com sends a 302 response, the Location header needs to be rewritten and have "/search" prepended in order to work. Of course, this works in Apache, but I'd rather have my whizzy 3400s do the work.
Any suggestions?
- gomes_127447Historic F5 AccountI'm not completely familiar with ProxyPass as I'm not an Apache admin.
- bl0ndie_127134Historic F5 AccountWhy don't you just add a rule that does a "HTTP::header replace Location 'new value'" in the HTTP_RESPONSE event.
- Brandon_High_10
Nimbostratus
I've got it half way workign by rewriting the HTTP::uri before sending the request to the pool, but I still need to rewrite the response from the server. - One way of accomplishing this is to store the target pool in a local variable and check that on the response.
when HTTP_REQUEST { if { [ HTTP::uri ] starts_with "/search" } { HTTP::uri [ findstr [HTTP::uri] "/search" 7 ] pool search_pool set target_pool "search_pool" } else { pool static_pool set target_pool "static_pool" } }
when HTTP_RESPONSE { if { $target_pool == "search_pool" } { rewrite the location header } }
- unRuleY_95363Historic F5 AccountInstead of saving a string, I would recommend using an integer or boolean value.
set target_pool "search_pool"
set rewrite_reponse 1
if { $rewrite_reponse } {
- unRuleY_95363Historic F5 AccountI would also suggest using [string range ...] instead of the findstr as you already know that the uri starts with /search.
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/search" } { HTTP::uri [string range [HTTP::uri] 7 end] pool search_pool set rewrite_response 1 } else { pool static_pool set rewrite_response 0 } }
when HTTP_RESPONSE { if { $rewrite_response } { rewrite the location header } }
- Brandon_High_10
Nimbostratus
Excellent, it's working now. It wasn't celar to me that a variable set during a HTTP_REQUEST even would still be set during the HTTP_RESPONSE. - unRuleY_95363Historic F5 AccountTry this modification to take care of your empty string problem:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/search" } { set new_uri [string range [HTTP::uri] 7 end] if { not $new_uri starts_with "/" } { set new_uri "/$new_uri" } HTTP::uri $new_uri pool search_pool set rewrite_response 1 } else { pool static_pool set rewrite_response 0 } }
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