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

Vaughn_96017's avatar
Vaughn_96017
Icon for Nimbostratus rankNimbostratus
Jun 27, 2007

Redirect based on user browser (mobile)

I am writing an iRule that states if the user is coming in via a mobile device to get redirected to a different pool. My question, here is what I have, is this correct?

 

 

when HTTP_REQUEST {

 

if {[HTTP::header User-Agent] contains "Mozilla"}

 

{pool default-pool} else {pool mobile-pool}

 

 

I was givin a list of known mobile user agents to look for but wouldn't it be easier to just look for the non mobile user agents?

 

 

Version 9.4 HF4

 

13 Replies

  • Indeed, "return 0" gets rid of the error 😄

    
    when HTTP_REQUEST {
     if {([string tolower [HTTP::host]] contains "my.com")} {
      switch -glob [HTTP::header User-Agent] {
       "*BlackBerry*" -
       "*Blackberry*" -
       "*Java/1.4.1_02*" -
       "*Blazer*" -
       "*blazer*" -
       "*palm*" -
       "*Palm*" -
       "*SMARTPHONE*" -
       "*Smartphone*" -
       "*smartphone*" -
       "*Danger*" -
       "*hiptop*" -
       "*MOT-*" -
       "*RAZR*" -
       "*AUDIOVOX*" -
       "*Symbian*" -
       "*symbian*" -
       "*NOKIA*" -
       "*Nokia*" -
       "*Sony Ericsson*" -
       "*Samsung*" -
       "*LG 8*" -
       "*Alcatel 735i*" -
       "*Nextel*" -
       "*Windows CE*" -
       "*NetFront*" { 
        pool mobile_pool
        return 0
       }
      } 
      switch -glob [HTTP::header Accept] {
       "*text/vnd.wap.wml*" { 
        pool mobile_pool
       }
      }
     }
    }

    edit: Used the wrong rule, is correct now
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    I assume the request you expect to be redirected but isn't being redirected is being made with a host header which matches *mobile*, but isn't a mobile user-agent. Here are a few modifications to your version. You could use the logging in this example to troubleshoot your version.

     
      
     when HTTP_REQUEST { 
      
        log local0. "[IP::client_addr]:[TCP::client_port]: New request from [HTTP::header User-Agent]\ 
           to [HTTP::host][HTTP::uri]" 
      
        if {([string tolower [HTTP::host]] contains "mobile")} {  
           switch -glob [string tolower [HTTP::header User-Agent]] { 
              "*blackberry*" -  
              "*java/1.4.1_02*" -  
              "*blazer*" -  
              "*palm*" -  
              "*smartphone*" -  
              "*danger*" -  
              "*hiptop*" -  
              "*mot-*" -  
              "*razr*" -  
              "*audiovox*" -  
              "*symbian*" -  
              "*nokia*" -  
              "*sony ericsson*" -  
              "*samsung*" -  
              "*lb 8*" -  
              "*alcatel 735i*" -  
              "*nextel*" -  
              "*windows ce*" -  
              "*netfront*" {   
                 pool mobile_pool 
                 log local0. "[IP::client_addr]:[TCP::client_port]: Matched Host and User-Agent checks" 
              } 
              default { 
                  Request didn't match User-Agent check 
                 HTTP::redirect "http://non_mobile_website.com" 
                 log local0. "[IP::client_addr]:[TCP::client_port]: Request didn't match User-Agent check" 
              } 
           } 
        } else {  
            Request didn't match Host header check 
           HTTP::redirect "http://non_mobile_website.com" 
           log local0. "[IP::client_addr]:[TCP::client_port]: Request didn't match Host check" 
        }  
     }  
     

    Aaron