Forum Discussion
URL rewrite through iRule
- Nov 11, 2013
Hi Sunnyman,
This will work;
if { [IP::addr [IP::client_addr] equals 1.1.1.1] || [IP::addr [IP::client_addr] equals 1.1.1.2} { SNAT with 1.1.1.100 snatpool VM_SNAT_POOL_1_1_1_100 } elseif { [IP::addr [IP::client_addr] equals 1.1.1.11] || [IP::addr [IP::client_addr] equals 1.1.1.12} { SNAT with 1.1.1.100 snatpool VM_SNAT_POOL_1_1_1_200 }
But that's not a very scalable way of doing it if your list is going to grow. If it's going to grow then use an address datagroup, with values snatpool names, which you can use like this
snatpool [class match -value [IP::remote_addr] equals dg_sunnyman_snatpools]
or more correctly;
set snatpool [class match -value [IP::remote_addr] equals dg_sunnyman_snatpools] if {$snatpool ne "") { snatpool $snatpool }
So do you really need to change the Host header at all? It has no effect on where the F5 sends the traffic BTW.
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] starts_with "abc.com" && [string tolower[HTTP::path]] eq "/ukm"} {
This pool needs to be created with pool member 1.1.1.1:8080
pool pl_sunnyman_8080
HTTP::uri "/xyz"
}
}
when LB_SELECTED {
This will update the Host header with the IP:port of the selected server
HTTP::header replace Host "[LB::server addr]:[LB::server port]"
}
This way when you want to add more servers into your pool, the Host header will get rewritten with whatever server got chosen from the pool, but as I said, unless you have a particular reason to rewrite the Host header I wouldn't bother - it has no effect on routing.
Recent Discussions
Related Content
* 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