Forum Discussion

Mukund_125243's avatar
Mukund_125243
Icon for Nimbostratus rankNimbostratus
Aug 15, 2013

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

  • Correction: the specific IP is the only ones that should get to the page - I stated the requirement incorrectly.

     

  • BinaryCanary_19's avatar
    BinaryCanary_19
    Historic F5 Account

    With redirects, you have to specify the full url, including the protocol (http/https)

     

    • Andres_4712's avatar
      Andres_4712
      Historic F5 Account
      Actually, 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.
  • 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]
        }
    }
    
    • Mark_Stradling_'s avatar
      Mark_Stradling_
      Icon for Cirrus rankCirrus
      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]"