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...
Nicolas_Menant
Employee
May 15, 2008Hi,
I would advise not to use matches_regex since it will take more CPU. Regular expression is really CPU expensive:
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"
}
}
In this code [HTTP::path] will return the Path AND the object name. May it be the reason why it doesn't match? Click here
You should try to replace the eq by contains or starts_with w(starts_with will be more efficient)
Can you update your iRule with troubleshooting information and give us the logging (is it in /var/log/ltm)
when HTTP_REQUEST {
log local0. "---------NEW REQUEST--------------"
log local0. "uri is: [HTTP::uri]"
log local0. "IP is: [IP::remote_addr]"
if { [string tolower [HTTP::uri]] starts_with "/foo/"} {
log local0. "Starting uri with /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])
} {
log local0. "sending to pool FOO.com-80"
pool FOO.com-80
}
} elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } {
log local0. "Redirecting user..."
HTTP::redirect "http://www.NEW.com"
} else {
log local0. "No matched occured for this request"
}
}
I added a last else statement for more logging information. Once it is fixed you should of course remove it
HTH
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