Irule to redirect based on both IP and URI else default
Hey folks,
I am trying to write an Irule that redirects based on IP & URI. So I want to say if you are coming from this IP 1.1.1.1 and your URI contains /notcool then redirect to a URL, otherwise just send to the default pool. I have tried a few things and can get it to work for just the IP or just the URI but when I combine them I get no love.
Here is what I am working on.
This one below if I do the
if { $http_uri starts_with "/notcool"} on its own OR if I do
if { $client_ip equals "1.1.1.1"} without any mention of the other I am good,
but when I get greedy and try to do both that's when it falls apart.
when HTTP_REQUEST {
set http_uri [HTTP::uri]
set client_ip [IP::client_addr]
if { $http_uri starts_with "/notcool"}{
if { $client_ip equals "1.1.1.1"}{
HTTP::redirect "https://coolnewpage.com/supercool"
}
else
{
pool notcool_pool
}
}
}
I also tried doing it like
when HTTP_REQUEST {
set http_uri [HTTP::uri]
set client_ip [IP::client_addr]
if ( { $http_uri starts_with "/notcool"} && {$client_ip equals "1.1.1.1"}) {
HTTP::redirect "https://coolnewpage.com/supercool"
}
else
{
pool notcool_pool
}
}
}
I appreciate any help you gurus can lend.
Thank you!
Joe
Sorry, try this. Couldn't quite remember where to put the parentheses.
when HTTP_REQUEST {
if { ([HTTP::uri] starts_with "/notcool") && ([IP::client_addr] equals "1.1.1.1")} {
HTTP::redirect "https://coolnewpage.com/supercool"
}
else
{
pool notcool_pool
}
}
}