Forum Discussion
Sylvain_85827
Jul 05, 2013Cirrus
Hi,
For information here is the current version of the iRule, thanks for your help to support me to get there. However I still need some help to solve the last issue which is rewriting the Location header, only the domain part and not the rest (ie. path and parameters). Note: I don't know why the feature in http profile did not work so I decided to make it within this iRule.
when RULE_INIT
Log debug messages to /var/log/ltm? 1=yes, 0=no
set static::rewrite_debug 1
External hostname for the web application
set static::external "newHost.com"
}
when HTTP_REQUEST_SEND {
Need to force the host header replacement and HTTP:: commands into the clientside context
as the HTTP_REQUEST_SEND event is in the serverside context
clientside {
Different action depending on the node selected for load-balancing
switch [LB::server addr] {
"1.1.1.1" {
HTTP::header replace Host "MyHost01"
if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: HTTP Host header rewritten with MyHost01"} }
"1.1.1.2" {
HTTP::header replace Host "MyHost02"
if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: HTTP Host header rewritten with MyHost02"} }
}
}
}
when HTTP_RESPONSE {
Replace all internal Host headers with $static::external value defined in RULE_INIT section
HTTP::header replace Host $static::external
if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: HTTP Host header rewritten with -> $static::external"}
if { [HTTP::is_redirect] } {
HTTP::header replace Location [string map -nocase "MyHost01.domainname.com newHost.com" [HTTP::header value Location]]
HTTP::header replace Location [string map -nocase "MyHost02.domainname.com newHost.com" [HTTP::header value Location]]
etc... --> Here I'm looking for a regex to replace the Location header in a single line while concatening the rest of Location value (i.e. with the part after https://domain_name/)
}
}
In a nutshell, now it only remains after [HTTP::is_redirect] to replace the domain name into the Location header in a single line thanks to a regex. For me more easy to say than to do 🙂 That's why I'm still here, asking for your valuable help guys (and girls).
Like this, I won't need to have as much lines as there are backend servers. Once done, we'll can consider this iRule as complete.
I hope I've been clear enough 🙂
Thanks again for your help.