Forum Discussion

Skuba_85554's avatar
Skuba_85554
Icon for Nimbostratus rankNimbostratus
Oct 13, 2010

is this line correct?!

hi everyone

 

 

could you confirm whether line 2 is correct? it only used to contain "www.abc.com" but i've added the "or" statement and i'm not sure if it's entirely correct...

 

 

---------------------------------------------

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::host]] starts_with "www.abc.com" or "www.def.com"} {

 

if { [string tolower [HTTP::uri]] contains "secure" } {

 

HTTP::redirect https://[HTTP::host][HTTP::uri]

 

}

 

elseif { [matchclass [string tolower [HTTP::uri]] starts_with $::redirect_class] } {

 

HTTP::redirect https://[HTTP::host][HTTP::uri]

 

}

 

else {

 

use pool my_pool

 

}

 

}

 

else {

 

use pool my_pool

 

}

 

---------------------------------------------

 

 

thank you

 

2 Replies

  • Hey Skuba,

    I believe you'll need to actually define the whole criteria again. For example:

    
          if { ([string tolower [HTTP::host]] starts_with "www.abc.com") or ([string tolower [HTTP::host]] starts_with "www.def.com")} {

    It probably isn't critical, but you might want to perform the tolower to make a variable instead of performing the operation twice

    
          set hostval [string tolower [HTTP::host]]
          if { ($hostval starts_with "www.abc.com") or ($hostval starts_with "www.def.com")} {

    I believe that the example you used would do is evaluate if "www.def.com" is true - which it should always be (i.e. similar to a "while true" statement). There are some more details on the 'or' operator here, too: http://devcentral.f5.com/wiki/default.aspx/iRules/or.html

    // Ben

  • Good info Ben. You could also use a switch statement to check the host value set to lowercase:

    
    switch [string tolower [HTTP::host]] {
       "www.abc.com" -
       "www.def.com" {
           Exact match for www.abc.com or www.def.com
       }
       default {
           No match
       }
    }
    

    Aaron