For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Greg_33932's avatar
Greg_33932
Icon for Nimbostratus rankNimbostratus
Feb 27, 2014

IRule - combine 2 variables with an and && statment

Having issues with an irule. I'm no where an expert so please forgive my ignorance. Everything else works but the following statement (bolded is the new portion, rest is working): if { ( $redirect_to_mobile == "true" && [matchclass [$lower_uri] starts_with $group] } {

Basically I want to detect the user browser (iphone, etc.) AND detect the url they are hitting and based on that forward them to the mobile friendly site.

Complete IRule:

when HTTP_REQUEST {

Set the user-agent field to all lower case so that the data group matches are not case sensitive

set user_agent [string tolower [HTTP::header User-Agent]] set non_mobile_pool "www.ddd.com" set mobile_url "http://m.ddd.com" set redirect_to_mobile "false" set group $::group_web_uri_dddMobile

Determine if the user agent (all lower case) is a member of the data group if { [matchclass $user_agent contains $::group_web_mobile_user_agents] } { log local0. "dddMobile - User-agent ($user_agent) is a member of the group_mobile_user-agents data group" set redirect_to_mobile "true"

   Check to see if it is an Android tablet. If it is, do not send it to the mobile site
  if { ( $user_agent contains "android" ) && not ( $user_agent contains "mobile" ) } {
      log local0. "dddMobile - User-agent ($user_agent) contains Android but is not Mobile"  
     set redirect_to_mobile "false"
  }

} else { log local0. "dddMobile - User-agent ($user_agent) is NOT a member of the group_mobile_user-agents data group" set redirect_to_mobile "false" }

Now send the request to the appropriate destination based upon the value of the redirect_to_mobile variable if { ( $redirect_to_mobile == "true" && [matchclass [$lower_uri] starts_with $group] } { HTTP::redirect "$mobile_url[HTTP::uri]"

} else { pool $non_mobile_pool }

}

13 Replies