Forum Discussion
pedinopa_170325
Nimbostratus
Sep 22, 2016irule redirection
I am trying to get the irule to redirect to a different default page. I have turned on logging and it appears that for some reason even though my client IP matches the condition in my if statement. ...
VernonWells
Employee
Sep 22, 2016Reformatted:
when HTTP_REQUEST {
if { ( [IP::addr [IP::client_addr] equals x.x.x.x]) } {
if { [HTTP::uri] equals "/index.htm" } {
log local0. "Client: [IP::client_addr]"
HTTP::redirect "http://[getfield [HTTP::host] ":" 1]/index_new.htm"
}
}
else {
log local0. "not redirecting client: [IP::client_addr]"
}
}
Although this isn't your issue, I will say that the
IP::addr [IP::client_addr] ... construct is not needed. IP::client_addr evaluates to a string, so, if you're comparing it to a single host address, equals is sufficient.
I recommend logging both the client addres and the Request-URI before the logic. Also, you may wish to consider using
HTTP::path rather than HTTP::uri. The latter would include, for example, any query parameters. So, you might try something like this:
when HTTP_REQUEST {
log local0. "Received request from ([IP::client_addr]) for ([HTTP::path])"
if { [IP::client_addr] eq "x.x.x.x" and [HTTP::path] equals "/index.htm" } {
log local0. " .. match branch"
HTTP::redirect "http://[getfield [HTTP::host] : 1]/index_new.htm"
}
else {
log local0. " .. miss branch"
}
}
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