Forum Discussion

Joseph_Johnson_'s avatar
Joseph_Johnson_
Icon for Nimbostratus rankNimbostratus
Feb 27, 2015

iRule redirect to mobile site

Hi,

I'm trying to create an iRule that will redirect users to site "www.mobilesite.com/slm/faces/m/index.jspx" if on mobile device else redirect to "https://mysite.com/OLA/faces/siteLocator.jspx". So far I have:

when HTTP_REQUEST {

if { [string tolower [HTTP::host]] contains "www.mobilesite.com"}{

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

        "*ipad*" -
        "*iphone*" -
        "*android*" -
        "*windows phone*" -
        "*windows ce*" -
        "*bada*" -
        "*bb10*" -
        "*blackberry*" -
        "*symbinos*" -
        "*symbain os*" -
        "*symbian*" -
        "*java*" -
        "*winowsphone*" -
        "*windowsce*" {
                HTTP::redirect "www.mobilesite.com/slm/faces/m/index.jspx"
            return
            }

        }


}

}

5 Replies

  • when HTTP_REQUEST {

    set uri [string tolower [HTTP::uri] ]

    set mobile_site "https://www.mobilesite.com"

    set full_site "http://www.mobilesite.com?Ismain=true"

    if {$uri contains "ismain=true" || $uri contains "xyzuri" || $uri contains "dynamicweb"} {

    event disable

    } else {

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

    "iphone" -

    "android" -

    "windows phone" -

    "*windows ce*" -
    
    "*bada*" -
    

    "bb10" -

    "blackberry" -

    "symbinos" -

    "symbain os" -

    "symbian" -

    "java" -

    "winowsphone" -

    "*windowsce*" {
    
     HTTP::redirect "https://www.mobilesite.com"
    
     return
    
     }
     }
     }
     }
    
  • when HTTP_REQUEST {

    set uri [string tolower [HTTP::uri] ]

    set mobile_site "https://www.mobilesite.com"

    set full_site "http://www.mobilesite.com?Ismain=true"

    if {$uri contains "ismain=true" || $uri contains "xyzuri" || $uri contains "dynamicweb"} {

    event disable

    } else {

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

    "iphone" -

    "android" -

    "windows phone" -

    "*windows ce*" -
    
    "*bada*" -
    

    "bb10" -

    "blackberry" -

    "symbinos" -

    "symbain os" -

    "symbian" -

    "java" -

    "winowsphone" -

    "*windowsce*" {
    
     HTTP::redirect "https://www.mobilesite.com"
    
     return
    
     }
     }
     }
     }
    
  • I think with your iRule, you'll wind up in an endless loop for mobile clients unless you add a URI check for the redirect page. And I'm assuming that if the user agent isn't for a mobile client, you want to redirect them to the page you mentioned... Maybe something like this would work

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] contains "www.mobilesite.com"}{
            switch -glob [string tolower [HTTP::header User-Agent]] {
                "*ipad*" -
                "*iphone*" -
                "*android*" -
                "*windows phone*" -
                "*windows ce*" -
                "*bada*" -
                "*bb10*" -
                "*blackberry*" -
                "*symbinos*" -
                "*symbain os*" -
                "*symbian*" -
                "*java*" -
                "*winowsphone*" -
                "*windowsce*" {
                    if {not ([string tolower [HTTP::uri]] equals "/slm/faces/m/index.jspx")} {
                        HTTP::redirect "www.mobilesite.com/slm/faces/m/index.jspx"
                        return
                    }
                }
                default {
                    HTTP::redirect "https://mysite.com/OLA/faces/siteLocator.jspx"
                }
            }
        }
    }