Forum Discussion
Sean_Lagerholm_
Nimbostratus
Jun 07, 2006Simple http redirect???
Help, I'm having difficulty with fulfilling a requirement :
The customer wants to type in some url and then gets redirected.
The customer doesn't want to see the redirect in their browser.
It should work like this :
in the browser type : http://somesite.com
The request gets proxied by the BigIP to http://anothersite.com/stuff
(the client never sees the http://anothersite.com/stuff in their browser.
Is this a redirect or a rewrite???
Thanks!!!
- Thomas_Uczekaj_
Nimbostratus
You can do this by the following: - Deb_Allen_18Historic F5 AccountTom -
and if you want to prepend /stuff to every URI, something like this would work:when HTTP_REQUEST { if { [HTTP::uri] equals "/"} { HTTP::uri /stuff } HTTP::header replace Host: anothersite.com }
when HTTP_REQUEST { if { [string length [HTTP::uri]] > 1 } { HTTP::uri /stuff[HTTP::uri] } else { HTTP::uri /stuff } HTTP::header replace Host: anothersite.com }
- Sean_Lagerholm_
Nimbostratus
Deb, - Deb_Allen_18Historic F5 AccountHey guys --
That should be pretty close to what you need. If you run into anomalies, adding some log lines to expose the variable values at different points in the code should help you work it out the rest of the way. But if you get stuck, feel free to post back with questions.class ProxyPass { space delimited row for each virtual to which rule will be applied vs_name backend_host_header backend_uri_prefix virtual1 inside_app1.company.com:7005 /newDir/otherDir virtual2 inside_app2.company.com:7006 /newDir/otherDir } rule ProxyPass { when HTTP_REQUEST { set ppass [findclass [virtual name] $::ProxyPass] if {$ppass == ""}{ log local0. "No ProxyPass class entry found for virtual server \ [virtual name] at [IP::local_addr]:[TCP::local_port]. \ Bypassing rewrite logic." set bypass 1 return } else { set host_clientside [HTTP::header Host] set host_serverside [getfield $ppass " " 1] set uri_prepend [getfield $ppass " " 2] HTTP::uri $uri_prepend[HTTP::uri] HTTP::header replace Host: $host_serverside } } when HTTP_RESPONSE { if { 1 != $bypass }{ set length [HTTP::header Content-Length] HTTP::collect $length regsub -all $host_serverside$uri_prepend [HTTP::payload] $host_clientside newdata HTTP::payload replace 0 $length $newdata HTTP::release unset newdata } } }
- Sean_Lagerholm_
Nimbostratus
Deb, - Sean_Lagerholm_
Nimbostratus
Deb, - Colin_Walker_12Historic F5 AccountThe class isn't actually part of the iRule.
class ProxyPass { space delimited row for each virtual to which rule will be applied vs_name backend_host_header backend_uri_prefix virtual1 inside_app1.company.com:7005 /newDir/otherDir virtual2 inside_app2.company.com:7006 /newDir/otherDir }
portion, and the closing brace that matches it.rule ... {
- Sean_Lagerholm_
Nimbostratus
Colin, - unRuleY_95363Historic F5 AccountThe above rule is not complete. You should search the forum or check out the Docs & Tips sections on replacing content. There are several good examples on methods to replace the content in a response.
- Deb_Allen_18Historic F5 AccountOk, I did a bit more reading & see that at least I need to move some of the response logic into an HTTP_RESPONSE_DATA event:
when HTTP_RESPONSE { if { 1 != $bypass }{ set length [HTTP::header Content-Length] HTTP::collect $length } } when HTTP_RESPONSE_DATA { if { 1 != $bypass }{ regsub -all $host_serverside$uri_prepend [HTTP::payload] $host_clientside newdata HTTP::payload replace 0 $length $newdata unset newdata } }
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