Forum Discussion
Sep 06, 2016
HTTP reverse proxy irule help
I currently have an irule that redirects a specific URI to a third party site while rewriting the headers to keep the original URL in the address bar. Currently, the URIs are required to match betwe...
Kai_Wilke
MVP
Sep 07, 2016Hi Joseph,
you may use the iRule below as a starting point...
when CLIENT_ACCEPTED {
Store the default pool name
set default_pool [LB::server pool]
set orig_hostname "www.abc.com"
set orig_base_uri "/en-gb/jobs"
set new_hostname "www.xyz.com"
set new_base_uri "/en-gb"
}
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] starts_with $orig_base_uri } then {
HTTP::header replace Host $new_hostname
if { [set dest [lindex [RESOLV::lookup @208.67.222.222 -a [HTTP::host]] 0]] ne "" } then {
node $dest
set rewrite_enabled 1
} else {
HTTP::redirect "/dns-error.html"
set rewrite_enabled 0
}
} else {
pool $default_pool
set rewrite_enabled 0
}
STREAM::disable
}
when HTTP_RESPONSE {
if { $rewrite_enabled } then {
if { [set location [HTTP::header value "Location"]] ne "" } then {
HTTP::header replace "Location" [string map [list $orig_hostname $new_hostname $orig_base_uri $new_base_uri] $location]
}
STREAM::expression "@$orig_hostname@$new_hostname@@$orig_base_uri@$new_base_uri@"
STREAM::enable
}
}
Note: I've streamlined some parts of the original iRule and also remove some parts which may cause trouble.
Note: Make sure to use a ONECONNECT profile on your Virtual Server to switch the
/[node]
on each request. Also make sure to use a COMPRESSION profile on your Virtual Server with "Keep Accept Encoding" option DISABLED.[pool]
Cheers, Kai
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
