Forum Discussion

VFB's avatar
VFB
Icon for Cirrus rankCirrus
Mar 14, 2014

redirecting L7 traffic

I'm trying to figure out how to redirect a set of L7 traffic host headers. Here's what I'd like to do:

 

redirect http://test.me.com to https://test.me.com, but all other traffic (example, johnny.test.com) should stay with http. any assistance would be greatly appreciated.

 

14 Replies

  • Eventually, I'd be adding johnny.test.com to redirect as well, but at this moment, it should remain http. How would I add it down the road to the same iRule?
  • Try this:

    when HTTP_REQUEST {
            if { [string tolower [HTTP::host]] equals "test.me.com" } {
               HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
            }   
        }
    
    • VFB's avatar
      VFB
      Icon for Cirrus rankCirrus
      Thanks much! How would I modify the iRule to add more urls to reredirected to https and let's say pool1 instead of pool2?
  • To do pool selection based on host, try something like this:

    when HTTP_REQUEST {
      switch -glob [HTTP::host] {
        "www.company.com" -
        "www.company3.com" -
        "foo.company.com" -
        "bar.company.com" - {
           pool mypool1   
        }
        default {
          pool mypool2
        }
      }
    }
    
    • VFB's avatar
      VFB
      Icon for Cirrus rankCirrus
      thanks for your help thus far. you have the switch -glob part in there but you left out rewriting them to https (www.company.com - bar.company.com)
    • Cory_50405's avatar
      Cory_50405
      Icon for Noctilucent rankNoctilucent
      Apologies, thought you were looking to direct to a pool based on hostname. To use a switch to redirect, just replace 'pool mypool1' with 'HTTP::redirect "https://test.me.com"
  • Additionally, add the "string tolower" on the switch statement so that these will match even if the user enters the host name in all caps or something.

     

    switch -glob [string tolower [HTTP::host]]

     

    Joe

     

    • VFB's avatar
      VFB
      Icon for Cirrus rankCirrus
      Does this look correct? when HTTP_REQUEST { switch -glob [HTTP::host] { "www.company.com" - "www.company3.com" - "foo.company.com" - "bar.company.com" - { HTTP::redirect "https://$host/" pool mypool1 } default { pool mypool2 } } }
    • VFB's avatar
      VFB
      Icon for Cirrus rankCirrus
      forgot the case sensitive piece when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]]{ "www.company.com" - "www.company3.com" - "foo.company.com" - "bar.company.com" - { HTTP::redirect "https://$host/" pool mypool1 } default { pool mypool2 } } }
  • Close. If all non-redirected traffic goes to the same pool then just let this be the redirect irule.

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::host]]{
        "www.company.com" -
        "www.company3.com" -
        "foo.company.com" -
        "bar.company.com" - {
          HTTP::redirect "https://[HTTP::host][HTTP::uri]"
        }
      }
    }
    

    Joe

    • VFB's avatar
      VFB
      Icon for Cirrus rankCirrus
      that's the thing - it doesn't. http traffic goes to 1 pool and https traffic goes to another pool.
  • These should probably be different VIPs anyway. An HTTP VIP pointing to the HTTP pool. This HTTP VIP will have this iRule tied to it to redirect as needed.

     

    Then a HTTPS VIP pointing to the HTTPS pool.

     

    Joe

     

    • VFB's avatar
      VFB
      Icon for Cirrus rankCirrus
      I tested the following on my VMWARE simulator and it worked. Just wanted to see if it would work in a real life environment - when HTTP_REQUEST { switch -glob { [string tolower [HTTP::host]] } { "test.me.com" - "yahoo.com" - [HTTP::redirect https://$host/] } }