Forum Discussion
Chris_Schaerli_
Nimbostratus
May 12, 2008Redirect or rewrite?
Hi,
I am trying to setup something to direct traffic based on source IP. We are rolling out an application and we want to do it in phased approach.
This is wha...
Colin_Walker_12
May 14, 2008Historic F5 Account
The first line looks fine, but I did make the mistake of assuming that you could use the IP::addr command in this way. Since the IP::addr command takes two arguments, you won't be able to use it in a switch statement. That means you'll have to use a series of if/else comparisons if you want to compare network ranges with multiple destinations. Since your example only uses a single pool as a destination, you could use the or command instead of multiple ifs.
So, if you're just comparing single IP addresses, you could do so like:
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] eq "/foo/"} {
switch [IP::remote_addr] {
10.12.126.248 -
10.12.126.249 -
10.12.126.250 -
10.24.69.2 -
default {
pool FOO.com-80
}
}
} elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } {
HTTP::redirect "http://www.NEW.com"
}
}
If you need to compare network ranges, and therefore need the IP::addr command, you would want something more like:
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] eq "/foo/"} {
if {([IP::addr [IP::remote_addr] equals 10.12.126.248/255.255.255.255]) or
([IP::addr [IP::remote_addr] equals 10.12.126.249/255.255.255.255]) or
([IP::addr [IP::remote_addr] equals 10.12.126.250/255.255.255.255]) or
([IP::addr [IP::remote_addr] equals 10.24.69.2/255.255.255.255])
} {
pool FOO.com-80
}
} elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } {
HTTP::redirect "http://www.NEW.com"
}
}
Hopefully this helps,
Colin
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