Forum Discussion
Sylvain_85827
Cirrus
Jul 02, 2013Rewrite URL based on selected node for load-balancing
Dears iRules Gurus and community,
Once again I need your help ^^ I'm wondering how to rewrite an URL of HTTP requests (IPP in fact) depending on the node chosen for load-balancing the traffic. ...
Sylvain_85827
Cirrus
Jul 05, 2013Hi,
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.
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