Forum Discussion
HTTP::redirect restrictions?
Hi,
Im trying to redirect all requests from an IP to a specific page, to a completely new URL. The redirect works but it always goes to our base domain no matter what I specify as redirect target. IRule would probably explain the situation better
Lets say the page abc.php is on 'some-host.my-site.com'(some-host.my-site.com/abc.php), the Irule below only redirects to my-site.com, regardless of the fact I asked it to go to google.com instead. Any input would be helpful
The plan was to apply this to only the virtual server for 'some-host' since this rule should not apply to any other host behind the domain
when HTTP_REQUEST {
set http_path [HTTP::uri]
if {$http_path contains "/abc.php" } {
if {[IP::addr [IP::client_addr] equals xx.xx.xx.xx]}{
use pool some-host
}
else {
HTTP::redirect "www.google.com"
}
}
}
9 Replies
- Mukund_125243
Nimbostratus
Correction: the specific IP is the only ones that should get to the page - I stated the requirement incorrectly.
- BinaryCanary_19Historic F5 Account
try using
HTTP::redirect "http://www.google.com"
- Mukund_125243
Nimbostratus
Yup - that works! thanks
- BinaryCanary_19Historic F5 Account
With redirects, you have to specify the full url, including the protocol (http/https)
- Andres_4712Historic F5 AccountActually, no :) . For example if you simply want to redirect to a different URL you can only use something like: HTTP::redirect "/new_URI" Of course , the normal thing to do is to modify the URI on its flight ( HTTP::uri /new_uri ); however, could be the case in which we do need to actually send a redirect and get a fresh new request to this URI from the client.
- BinaryCanary_19Historic F5 AccountI meant when redirecting to a different domain.
- Andres_4712Historic F5 Accounthaha :)
It sounds like you want to preserve the URI portion of the original request. If so you would want to modify it as so:
HTTP::redirect "http://www.google.com[HTTP::uri]"I also use a little trick to ensure that I keep them on the same protocol the arrived on by doing the following:
when HTTP_REQUEST { if {[TCP::local_port] eq 80} { set proto "http" } elseif {[TCP::local_port eq 443} { set proto "https" } else { log local0. "UNKNOWN PORT!" } if {[HTTP::uri] contains "blah_blah_blah"} { HTTP::redirect $proto://www.google.com[HTTP::uri] } }- Also, note that the HTTP::redirect method will issue a 302 which is "Temporarily moved." It may not be appropriate for all applications. If you need to issue a redirect for "permanently moved" you will need to do the following: HTTP::respond 301 Location "http://www.google.com[HTTP::uri]"
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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