Forum Discussion
HTTP_REQUEST and HTTP::redirect and HTTP::respond with if condition and source IP
A few things to point out:
-
You don't need to set the src_client_ip variable because you're only evaluating it once. The added variable just adds memory consumption. Truthfully, since you're only evaluating the path 3 times, you could probably also skip setting the path variable as well.
-
Is the %1701 a route domain identifier?
-
In each of your conditions, you HTTP::redirect and HTTP::respond commands. The HTTP::redirect command issues a 302 response to the client with a Location header. The HTTP::response command, in this case, responds to the client with a 200 and some HTML content. These two commands are contradictory. If it works at all, it's certainly an anomaly.
-
I would add some logging to the top of your iRule to see what the path actually is. The fact that the "/use1/" condition isn't catching would most likely indicate that the path is never "/use1/".
Here's a new version of your iRule. I made some assumptions about what you wanted to do in the conditions where you had a redirect and a respond.
when HTTP_REQUEST {
log local0. "Client ([IP::client_addr]) is requesting: [HTTP::path]"
if { [IP::addr [IP::client_addr] equals 176.202.126.81%1701] } {
log local0. "Client IP match"
switch -glob [string tolower [HTTP::path]] {
"/use1/*" {
log local0. "Catch /use1/ - redirecting"
HTTP::redirect "https://ecr.host.com.qa/use/"
}
"/use/*" {
log local0. "Catch /use/"
HTTP::respond 200 content "IP is $src_client_ip and /use/" "Content-Type" "text/xml"
}
"/oncfo1/*" {
log local0. "Catch /oncf1/ - redirecting"
HTTP::redirect "https://ecr.host.com.qa/oncfo/"
}
"/oncfo/*" {
log local0. "Catch /oncfo"
HTTP::respond 200 content "IP is $src_client_ip and /oncfo/" "Content-Type" "text/xml"
}
"/oncres1/*" {
log local0. "Catch /oncres1/ - redirecting"
HTTP::redirect "https://ecr.host.com.qa/oncres/"
}
"/oncres/*" {
log local0. "Catch /oncres/"
HTTP::respond 200 content "IP is $src_client_ip and /oncres/" "Content-Type" "text/xml"
}
default {
log local0. "Default condition"
HTTP::respond 200 content "IP is $src_client_ip and check it" "Content-Type" "text/xml"
}
}
} else {
log local0. "Client IP doesn't match"
HTTP::respond 200 content "IP is $src_client_ip and check it" "Content-Type" "text/xml"
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
* 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