Forum Discussion
http header replace with host & redirect based on path
Hi,
I have written i-rule for http header replace and re-direction based on path but it is not working as expect. Please review the config and suggest what changes needs to be done for the below i-rule.
Actual i-rule :
when HTTP_REQUEST {
set hostname [string tolower [HTTP::host]]
pool pool_site1
if { $hostname equals "a.site1.commerce.example.com" } {
HTTP::header replace "Host" "a.site1.com"
} elseif { $hostname equals "a.services.commerce.example.com" && $uri == "/search/*" }{
pool pool_site_new
}
elseif { $hostname equals "a.site2.example.com"} {
pool pool_site2
}
if { [HTTP::cookie exists "MAT_PERFORMANCE_TEST"] } {
pool pool_site3
}
}
Above condition statements in irule are working fine but, for the below statement is not working as expected. My requirement is, if host name is a.services.commerce.example.com and path is "/search/ resources/store/12345/" it should redirect to pool_site_new and if path doesn't have /search/resource/... it should redirect to default pool or pool_site1.
elseif { $hostname equals "a.services.commerce.example.com" && $uri == "/search/*" }{
pool pool_site_new
}
>>>>>>> Also wanted to http header rewrite/replace rule in the same irule <<<<<<
Host header re-write
If header MAT_HOSTNAME = b.example.com
Replace host : b.example.com
and send to new pool pool_site4
Please help in correcting or suggesting the required changes.
Thanking you advance.
- Hamish
Cirrocumulus
I'd put brackets around compound comparisons myself. Removes ambiguity when you're reading it. e.g.
elseif { ($hostname equals "a.services.commerce.example.com") && ($uri == "/search/*") }{
Also (And this is probably you're actual issue) the operator == is EQUALS. So it'll only match if you actually request '/search/*'. What you want is a glob comparison. You want to use the operator 'matches_glob' instead.
- T_Rajneesh
Nimbostratus
Thanks Hamish
Will check above suggestion..can you also suggest header replace with host query ?
- T_Rajneesh
Nimbostratus
Hi Hamish,
The above one too not working as expected. Is there any other better way to write i-rule for the above mentioned ask ?
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