Forum Discussion

Chris_D_15752's avatar
Chris_D_15752
Icon for Nimbostratus rankNimbostratus
May 02, 2011

Mobile redirect with forced SSL

Hi guys,

 

 

I am faced with dual puzzle for site demending dual function redirect causing some issses.

 

I need to provide detection process from www.main.com site provide mobile type version/release services.

 

I establised individual VIP exposed and registered externally with m.main.com. Requests sourcing from mobile devices are detected and redirected to m.version VIP using script I enclosed below. It works well and relatively all devices are detected and rediected properly. All are happy and I still have the job. Problem develops with adding SSL force redirect after mobile deterction takes place. Standard http_https_redirect fails to complete after my first script runs.

 

 

Concept is relatively simple. All traffic to standard VIP is redirected to SSL. Same applies to mobile frame devices and they all need to be SSL forced.

 

 

Can you please share some light on single or dual step scripts you know work with this requirements?

 

I appreciate your help .

 

 

 

when HTTP_REQUEST {

 

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

 

"*blackberry*" -

 

"*windows ce*" -

 

"*palm*" -

 

"*sonyericsson*" -

 

"*lg*" -

 

"*sie*" -

 

"*up.b*" -

 

"*up*" -

 

"*motorola*" -

 

"*mot-*" -

 

"*astel;*" -

 

"*j-phone*" -

 

"*netfront*" -

 

"*xiino*" -

 

"*iphone*" -

 

"*benq*" -

 

"*cricket*" -

 

"*andr*" -

 

"*htc*" -

 

"*nokia*" -

 

"*portalmmm *" -

 

"*samsung*" -

 

"*sec*" -

 

"*vodafone*" -

 

"*smartphone*" -

 

"*symbian*" {

 

HTTP::redirect "]"

 

return

 

}

 

}

 

if { [string tolower [HTTP::header Accept]] contains "vnd.wap.wml" } {

 

HTTP::redirect "]"

 

return

 

}

 

if { [HTTP::header exists "MSISDN"] } {

 

HTTP::redirect "]"

 

return

 

}

 

 

 

 

 

28 Replies

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Rafael,

     

     

    Sure you can skip the cookie logic. If you only want to check for mobile clients on root requests, you can add the mobile client logic in an 'if' statement:

     

     

    if {[HTTP::path] eq "/"}{

     

    ... mobile agent checks

     

    }

     

     

    Aaron
  • Hi Aaron,

     

     

    So the iRule should look like:

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::path] eq "/"}{

     

    if {([HTTP::header "User-Agent"] contains "Ipod") or

     

    ([HTTP::header "User-Agent"] contains "Iphone")

     

    } {

     

    HTTP::redirect "http://m.mysite.com"

     

    pool mobile_pool

     

    }

     

    else {

     

    pool main_pool

     

    }

     

    }

     

    else {

     

    return

     

    }

     

     

    }

     

     

    Thank you

     

  • Rafael. Looking at your code, I'm not quite sure the need to establish the pool following the HTTP::redirect when a mobile device is detected (ahh somewhat limited to only an Ipod or Iphone as mobile). The redirect will issue a 302 response, which would essentially end further processing and therefore no resource pool would be touched.

     

     

    Just an observation as I'm comparing what we have done here to what is most recent on DevCentral.

     

  • Hi Guys

     

    I am in the same boat, and have been trying to do the cookie detection with no success.

     

    My scenario is as follows:

     

    I have two virtual servers

     

    blah.com and mobile.blah.com

     

    I can deploy the below irule on the blah.com vs and get only the agents I want to be redirected to the mobile site.

     

    On the mobile virtual server I am using persistence to drop a cookie called blah-mobilesite.

     

    On the mobile site developers have just put a link back to the main blah.com site.

     

    Kinda hard to trigger off.

     

    So i am figuring that if a client has been to the mobile site and picked up the blah-mobilesite cookie and then gone to the main site it is because they have been sent their by the link.

     

    Here is the rule I am working with atm.

     

     

     

    when HTTP_REQUEST {

     

    Check if the full site cookie preference has already been set

     

    if {[HTTP::cookie value "blah-mobilesite"] eq "*"}{

     

     

    Exit this event in this iRule to avoid a possible redirect to the mobile site

     

    return

     

    }

     

    ... rest of the iRule logic to check for mobile user-agents

     

    and redirect them to the mobile site

     

     

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

     

    "*blackberry*" -

     

    "*firefox*" -

     

    "*iphone*" -

     

    "*android*" {

     

    HTTP::redirect "http://mobile.blah.com/"

     

    return

     

    }

     

    }

     

    }

     

     

    I have checked and the client does receive the blah-mobilesite cookie when they visit the mobile site.

     

    I just can't seem to make the irule detect that they have it.

     

    Any suggestions would be greatly appreciated, I think I am clearly missing something here.

     

     

    btw I have just included firefox to make testing easier.
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    Luke

     

     

    Have you tried using HTTP:cookie exists instead? Just in case it doesn't like the value setting?

     

     

    Try:

     

     

    if { [HTTP::cookie exists blah-mobilesite] } {

     

     

    Hope this helps,

     

    N
  • Hi Nathan

     

    Good idea.

     

    Just tried that but it did not work either.

     

    Maybe the cookie is disappearing when the user goes back to the main site as it is only a session cookie.

     

    Something does not seem right here.

     

     

     

  • I got a easy solution if you like. Set the redirect back link on mobile site to different VS then the current VS :)

     

  • Hi,

    here are two irules you can use:

    redirect URL based (user agent are those defined as default in TMG to identify mobile / full user agents)

    when HTTP_REQUEST {
       set clientless_mode 0
        Check the requested HTTP Host
       if {[HTTP::host] equals "site.com"} {
            Identify User-Agents type
            switch -glob [string tolower [HTTP::header "User-Agent"]] {
                "*blazer*" -
                "*docomo*" -
                "*windows ce*" -
                "*symbian os*" -
                "*sonyericsson*" { set clientless_mode 0 }
                "*frontpage*" { set clientless_mode 1 }
                "*mozilla*" -
                "*opera*" { set clientless_mode 0 }
                default { set clientless_mode 1 }
            }
       if { $clientless_mode} {
            HTTP::redirect "https://m.site.com[HTTP::uri]"
            return
            }
    
       } else {
            pool P_mobile
       }
    }
    

    redirect cookie based

    when HTTP_REQUEST {
       set clientless_mode 0
        Check the requested Cookie
       if { ![HTTP::cookie exists "MCookie"] } {
            Identify User-Agents type
            switch -glob [string tolower [HTTP::header "User-Agent"]] {
                "*blazer*" -
                "*docomo*" -
                "*windows ce*" -
                "*symbian os*" -
                "*sonyericsson*" { set clientless_mode 0 }
                "*frontpage*" { set clientless_mode 1 }
                "*mozilla*" -
                "*opera*" { set clientless_mode 0 }
                default { set clientless_mode 1 }
            }
       if { $clientless_mode} {
            HTTP::respond 302 noserver Set-Cookie "MCookie="mobile";path=/;secure" Location "https://m.site.com/"
            return
          } else {
            HTTP::respond 302 noserver Set-Cookie "MCookie="full";path=/;secure" Location "https://www.site.com/"
          }
    
       } elseif {[HTTP::cookie value MCookie] equals "mobile"} {
            pool P_mobile   
       }
    }
    

    Regards,

    Stanislas