Forum Discussion

acgutierrez_123's avatar
acgutierrez_123
Icon for Nimbostratus rankNimbostratus
Sep 12, 2013

iRule to deny traffic from local network AND redirect to HTTPS

Hi all, I have this iRule that's currently working to only allow traffic from a network segment if the http request contains a certain uri, I also want it to be redirected from http to HTTPS but I'm not sure how to insert a http::redirect to the current iRule. comments and advice are appreciated :)

 

when HTTP_REQUEST { if { ([HTTP::uri] contains "inscripcion-web") } then { if { [IP::addr [IP::client_addr] equals 192.168.147.0/24] } then { pool pool_.93y.94_8690_inscripcion-web } else { } } }

 

13 Replies

  • Here's a formatted version of the iRule:

    when HTTP_REQUEST { 
        if { [HTTP::uri] contains "inscripcion-web" } { 
            if { [IP::addr [IP::client_addr] equals 192.168.147.0/24] } { 
                pool pool_.93y.94_8690_inscripcion-web 
            } else { 
                 do nothing
            } 
        } 
    }
    

    So where and when do you want to redirect the user to HTTPS?

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account

    How about something like:

    when HTTP_REQUEST { 
      if { ([HTTP::uri] contains "inscripcion-web") and ([IP::addr [IP::client_addr] equals 192.168.147.0/24]) }  {  
        if {[TCP::local_port] == "443"} { 
          pool pool_.93y.94_8690_inscripcion-web 
        } else {
          HTTP::redirect "https://[HTTP::host][HTTP::uri]"
        }
      }    
    }
    

    Something like that should get what you're looking for, I believe.

    Colin

    • acgutierrez_123's avatar
      acgutierrez_123
      Icon for Nimbostratus rankNimbostratus
      ok, but the inicial request is HTTP, what I want is when the user types http://www.example.com/inscripon-web/ it redirects to https, is that possible with that iRule?
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account

    Yep. What will happen is if a user requests the page on HTTPS (port 443) it will just direct it to the pool as normal. If the request isn't coming in on HTTPS (I.E. not port 443) then it will redirect to the same host and URI combination but using HTTPS.

     

    Is that what you're looking for?

     

    Colin