Forum Discussion

chungyu_16122's avatar
chungyu_16122
Icon for Altostratus rankAltostratus
Jan 02, 2013

Redirects to a mobile site not being completed by iRule

Hi I wrote this irule, the redirect stops at http://desautels.mobilize.com and does not actually redirect to the full path desired, does anyone have a suggestion? I am using Chrome but with a user-agent switcher for testing.

 

 

Regards

 

 

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::host]] equals "www.mcgill.ca/desautels/programs/isp" } {

 

switch -glob [string tolower [HTTP::header User-Agent]] {

 

"*blackberry*" -

 

"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5 *"-

 

"*Android*" -

 

"*Windows Phone OS 7*" -

 

"*Windows Phone OS 8*"-

 

}

 

{

 

HTTP::redirect "http://desautels.mobilizeme.com/undergraduate_programs/isp"

 

}

 

}

 

}

 

9 Replies

  • Your if is wrong, you really need a space after the Mozilla line, before the hyphen and the redirect line is in the wrong place. Here's my rewrite;

    
    when HTTP_REQUEST {
     if { (([string tolower [HTTP::host]] equals "www.mcgill.ca") && ([string tolower [HTTP::uri]] equals "/desautels/programs/isp")) } {
      switch -glob [string tolower [HTTP::header User-Agent]] {
       "*blackberry*" -
       "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5*" -
       "*Android*" -
       "*Windows Phone OS*" { 
        HTTP::redirect "http://desautels.mobilizeme.com/undergraduate_programs/isp"
       }
      }
     }
    }
    
  • Personally I'd use a Data Group and do it like this;

    
    Create a Data Group (called user-agent-dg below) with just strings 
    containing the user agent strings you wish to match
    
    when HTTP_REQUEST {
     if { (([string tolower [HTTP::host]] equals "www.mcgill.ca") && ([string tolower [HTTP::uri]] equals "/desautels/programs/isp")) } {
      if { [class match [string tolower [HTTP::header User-Agent]] equals 
      user-agent-dg ] } { 
       HTTP::redirect "http://m.example.com" }
       Stop processing the iRule for this event here
       return
       }
    }
    
  • I'd also suggest you do a quick search here on DC for some better lists of possible mobile User-Agent strings.
  • Hey thanks for the quick response, I will look at both examples and try them out. Happy New Year too everyone out there.

     

     

    Chung

     

  • Hi I just tried this format, I am assuming the iRule should be using the & rather than ;amp However, i just get a page not found, rather than a redirect. when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals "www.mcgill.ca") & ([string tolower [HTTP::uri]] equals "/desautels/programs/isp")) } { switch -glob [string tolower [HTTP::header User-Agent]] { "*blackberry*" - "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5*" - "*Android*" - "*Windows Phone OS*" { HTTP::redirect "http://desautels.mobilizeme.com/undergraduate_programs/isp" } } } }
  • can you add some log command in the irule? traffic might not reach the HTTP::redirec command.
  • Thanks, that seems to get everything working properly, the only problem i still have is getting the right user-agent strings. When i use chrome as a Blackberry Bold, things are ok, but my iPHone or Android setting in Chrome don't seem to work. I tried looking up iphone user-agent string and plugged in *Apple-iPhone* but that does not seem to work at all. Chung
  • Hi chungyu,

     

     

    I agree with Nitass. You should put a logging statement in your iRule and see what User-Agents are being processed.

     

     

    log local0. "[HTTP::header User-Agent] Device Detected"

     

     

    For Testing you can use a Mozilla Plugin User-Agent-Switcher.

     

     

    A good place to get a list of User-Agents can be found here UserAgentString.com

     

     

    Hope this helps.