Forum Discussion
Kai_Wilke
Sep 07, 2016MVP
Hi 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