Forum Discussion

DAGOATMAMBA_328's avatar
DAGOATMAMBA_328
Icon for Nimbostratus rankNimbostratus
Aug 04, 2017

Auto redirect http to https for LB traffic

For traffic routing to the new LB solution, if there is no matching host on the HTTP endpoint, return a redirect to the client for them to try the same request on the HTTPS endpoint.....this is for a list of poolnames if that makes a difference

 

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    There's a standard iRule (_sys_https_redirect) provided by F5 for this. Unless you're doing this to learn, or you require some additional functionality, I would recommend you use that.

     

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Sorry, I missed that extra bit. It should be easy too. Chuck an extra iRule in ahead of the _sys_https_redirect. If you don't want the redirect to happen, then disable further events on that connection and force a close after the current request completes.

     

  • when HTTP_REQUEST {
    
        Check if Host header has a value
       if {[HTTP::host] eq ""}{
       pool pl_autos.dev.test.com 
    
    
    
    
    
    
    
    
    } else { HTTP::redirect https://[HTTP::host][HTTP::uri]  }  
    

    }

    • DAGOATMAMBA_328's avatar
      DAGOATMAMBA_328
      Icon for Nimbostratus rankNimbostratus

      This is what I have come up with.....So, it looks for the host that has no matching host header for the pool and if it doesnt have matching one it redirects it at the end to https with the same hostsS/

       

  • Anyone has a different Irule that'll work for if you no host is found for a poolname and redirect it to https? o

     

  • when HTTP_REQUEST { create a variable and change it everything to lowercase set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]] assign a pool name to the variable set Poolname "pl_www.testpool.org_80" set Irulename "Irule_www.testpool.org_80" Checking if the pool has active pools memebers set Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname] If there are no active pool members send it to outservice splash page if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean website site is down. IRULE=$Irulename"; HTTP::redirect "http://www.outservicepage.org."; } else { set list of host to match. if none of them match redirect to HTTPS switch $Vheader { testpool.org { pool $Poolname } { pool $Poolname }

        default {HTTP::redirect "https://[HTTP::host][HTTP::uri]"}
        }   
    }
    

    }

  • when HTTP_REQUEST {

     create a variable and change it everything to lowercase
    
    set Vuri [ string tolower [HTTP::uri]]
    
    set Vheader [string tolower [HTTP::host]]
    
    assign a pool name to the variable
    
    set Poolname "pl_www.testpool.org_80"
    
    set Irulename "Irule_www.testpool.org_80"
    
    Checking if the pool has active pools memebers
    
    set Poolmember [active_members $Poolname ] 
    
    set Poolmemberlist [ active_members -list $Poolname]
    
    If there are no active pool members send it to outservice splash page
    
    if {$Poolmember < 1} then {
        log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean website site is down. IRULE=$Irulename";
        HTTP::redirect "http://www.outservicepage.org."
    }
    else    
    {
    

    set list of host to match. if none of them match redirect to HTTPS

        switch $Vheader {
    
                testpool.org { pool $Poolname }
                www.testpool.org { pool $Poolname }
    
        default {HTTP::redirect "https://[HTTP::host][HTTP::uri]"}
        }   
    }
    

    }