Forum Discussion
Randy_Johnson_1
Nimbostratus
Nov 29, 2006Question on (what should be) a simple redirect -
Hi, group-
I have a set of URLs I'd like to redirect. My rule looks like this -
when HTTP_REQUEST {
log local0. "Checking URI [HTTP::uri] from [IP::client_addr] for insecure calls to some server"
if { [string tolower [HTTP::uri]] equals "https://someserver.somedomain.net/fooserver/foo"} {
HTTP::redirect "https://redirect.somedomain.net"
log local0. "Request for [HTTP::uri] from [IP::client_addr] is being sent to the Admin site"
}
}
From my BigIP logs, it appears as though the request is checked, and logging occurs. However, redirection does not occur.
Am I missing something ?
Thanks !
7 Replies
- hoolio
Cirrostratus
It looks like you're mixing our interpretation of URI and URL.
What does your log entry show for [HTTP::uri]? I would expect that the URI would be "/fooserver/foo", not "https://someserver.somedomain.net/fooserver/foo"
Are you trying to redirect if someone accesses the VIP through a bad hostname? If so, you should take a look at the [HTTP::host] value. If not, can you explain what you're trying to do?
Aaron - Randy_Johnson_1
Nimbostratus
You're correct about the URI logged being /fooserver/foo.
What I'm trying to do is if someone accesses the URI /fooserver/foo, on the virtual server this rule is applied to, then redirect them to a different URL.
I altered the rule to reflect the correct URI, but redirection does not occur.
when HTTP_REQUEST {
log local0. "Checking URI [HTTP::uri] from [IP::client_addr] for insecure calls to some server"
if { [string tolower [HTTP::uri]] equals "/fooserver/foo"} {
HTTP::redirect "https://redirect.somedomain.net"
log local0. "Request for [HTTP::uri] from [IP::client_addr] is being sent to the other site"
}
}
Thanks for your help ! - Can you post the log output from your log statements? Your code looks correct so without knowing the exact contents of the HTTP::uri value it's hard to guess at what is going wrong.
-Joe - Randy_Johnson_1
Nimbostratus
The rule logs this string:
Rule Randy_Test : Checking URI /fooserver/foo from 209.221.139.195 for insecure calls to some server
What happens is the the client continues on to the URL
https://someserver.somedomain.net/fooserver/foo
rather than being redirected to
https://redirect.somedomain.net - So is the second log statement not being reached? Since you only included the first log statement in your response I'm assuming the one in the enclosed if statement is not being reached. Is that a correct assumption. I have no clue on why a simple string comparison would not work.
I would recommend using log statements in all logic paths.when HTTP_REQUEST { log local0. "Checking URI '[HTTP::uri]' from [IP::client_addr] for insecure calls to some server" if { [string tolower [HTTP::uri]] equals "/fooserver/foo"} { log local0. "Request for '[HTTP::uri]' from [IP::client_addr] is being sent to the other site" HTTP::redirect "https://redirect.somedomain.net" } else { log local0. "Request for '[HTTP::uri]' from [IP::client_addr] is being allowed" } }
An alternate approach you could try would be something like this:when HTTP_REQUEST { log local0. "Checking URI '[HTTP::uri]' from [IP::client_addr] for insecure calls to some server" switch [string tolower [HTTP::uri]] { "/fooserver/foo" { log local0. "Request for '[HTTP::uri]' from [IP::client_addr] is being sent to the other site" HTTP::redirect "https://redirect.somedomain.net" } default { log local0. "Request for '[HTTP::uri]' from [IP::client_addr] is being allowed" } } }
The only thing I can think of if the equals operator isn't succeeding is that the original string has a space in it or something to make the equals not succeed. That's why I've included quotes in the log statement to help rule that out.
If it is actually getting to the HTTP::redirect command and that isn't in fact issuing a redirect to the client, then that's a product issue that you'll have to take up with product support.
Run one of these rules through and pass along the full log output and well see where we stand.
-Joe - Randy_Johnson_1
Nimbostratus
Thanks, Joe - The first sample works like a champ.
Not sure what was going on with my original, it just wasn't working. - Whewww. I was about to be stumped on that one...
Glad to hear it's working and feel free to ping us again if you get stuck on anything.
-Joe
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