Forum Discussion

Jacquesvd_10578's avatar
Jacquesvd_10578
Icon for Nimbostratus rankNimbostratus
Nov 30, 2015

Geolocation iRule,

Hi guys, maybe someone can assist me regarding this irule. Our client wants to do Geo Location using this irule.

Any suggestions from your side, its not working, I have tried a couple of different things already.

Thank you, Jacques.

when HTTP_REQUEST {

if { [string tolower [HTTP::host]] contains "marksandspencerme.com" && [HTTP::path] eq "/" }{

     Parse the client IP from the CDN header
    set client_ip [HTTP::header value "Client-IP"]
    if { $client_ip eq "" }{
         The header was empty/did not exist, so use the actual client IP
        set client_ip [IP::client_addr]
    }
    set country [string tolower [whereis $client_ip abbrev]]
    switch $country {
        "JO" -
        "EG" -
        "BH" -
        "KW" -
        "QA" -
        "OM" -
        "LB" {
            HTTP::redirect "http://www.marksandspencerme.com/-${country}"
        } 
        default {
             Redirect all others
            HTTP::redirect "http://www.marksandspencerme.com/"
        }
    }
} else {
    pool Pool_www.marksandspencerme.com_2.54_HTTP
}

}

2 Replies

  • 'string tolower' changes the country code to lowercase yet your switch statement is all in uppercase. Change to the following and give it a test:

     

    when HTTP_REQUEST {
    
    if { [string tolower [HTTP::host]] contains "marksandspencerme.com" && [HTTP::path] eq "/" }{
    
         Parse the client IP from the CDN header
        set client_ip [HTTP::header value "Client-IP"]
        if { $client_ip eq "" }{
             The header was empty/did not exist, so use the actual client IP
            set client_ip [IP::client_addr]
        }
        set country [string tolower [whereis $client_ip abbrev]]
        switch $country {
            "jo" -
            "eg" -
            "bh" -
            "kw" -
            "qa" -
            "om" -
            "lb" {
                HTTP::redirect "http://www.marksandspencerme.com/-${country}"
            } 
            default {
                 Redirect all others
                HTTP::redirect "http://www.marksandspencerme.com/"
            }
        }
    } else {
        pool Pool_www.marksandspencerme.com_2.54_HTTP
    }
    }
  • Are you look for the country or state? If country change the set country line to the following:

    set country [string tolower [whereis $client_ip country]]