Forum Discussion

THASIN's avatar
THASIN
Icon for Nimbostratus rankNimbostratus
Jan 18, 2012

GEOIP redirection irule

I just created one rule to redirect based on client Geo IP address.

 

 

I got timeout error message

 

 

 

Pls help me to resolve the issue.

 

 

 

when HTTP_REQUEST {

 

if { [[[string tolower [HTTP::host]] equals "www.example.com"] AND [[HTTP::uri] starts_with "" ]] }

 

{ 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]

 

}

 

switch [whereis $client_ip abbrev] {

 

"AF" {

 

Afganistan

 

HTTP::redirect "http://www.example.com/home-af"

 

}

 

"BH" {

 

 

Bahrain

 

HTTP::redirect "http://www.example.com/home-bh"

 

}

 

"BD" {

 

 

Bangladesh

 

HTTP::redirect "http://www.example.com/home-bd"

 

}

 

"BE" {

 

 

Belgium

 

HTTP::redirect "http://www.example.com/home-be"

 

}

 

"EG" {

 

 

Egypt

 

HTTP::redirect "http://www.example.com/home-eg"

 

}

 

"FR" {

 

 

France

 

HTTP::redirect "http://www.example.com/home-fr"

 

}

 

"DE" {

 

 

Germany

 

HTTP::redirect "http://www.example.com/home-de"

 

}

 

"IN" {

 

 

India

 

HTTP::redirect "http://www.example.com/home-in"

 

}

 

"IR" {

 

 

Iran

 

HTTP::redirect "http://www.example.com/home-ir"

 

}

 

"IQ" {

 

 

Iraq

 

HTTP::redirect "http://www.example.com/home-iq"

 

}

 

"IT" {

 

 

Italy

 

HTTP::redirect "http://www.example.com/home-it"

 

}

 

"JO" {

 

 

Jordon

 

HTTP::redirect "http://www.example.com/home-jo"

 

}

 

"KZ" {

 

 

Kazakhastan

 

HTTP::redirect "http://www.example.com/home-kz"

 

}

 

"KE" {

 

 

kenya

 

HTTP::redirect "http://www.example.com/home-ke"

 

}

 

"KW" {

 

 

Kuwait

 

HTTP::redirect "http://www.example.com/home-kw"

 

}

 

"LB" {

 

 

Lebanon

 

HTTP::redirect "http://www.example.com/home-lb"

 

}

 

"MO" {

 

 

Morocco

 

HTTP::redirect "http://www.example.com/home-ma"

 

}

 

"NP" {

 

 

Nepal

 

HTTP::redirect "http://www.example.com/home-np"

 

}

 

"NL" {

 

 

Netherlands

 

HTTP::redirect "http://www.example.com/home-nl"

 

}

 

"OM" {

 

 

Oman

 

HTTP::redirect "http://www.example.com/home-om"

 

}

 

"PK" {

 

 

Pakistan

 

HTTP::redirect "http://www.example.com/home-pk"

 

}

 

"QA" {

 

 

Qatar

 

HTTP::redirect "http://www.example.com/home-qa"

 

}

 

"RU" {

 

 

Russia

 

HTTP::redirect "http://www.example.com/home-ru"

 

}

 

"SA" {

 

 

Saudi Arabia

 

HTTP::redirect "http://www.example.com/home-sa"

 

}

 

"ES" {

 

 

Spain

 

HTTP::redirect "http://www.example.com/home-es"

 

}

 

"LK" {

 

 

Sri Lanka

 

HTTP::redirect "http://www.example.com/home-lk"

 

}

 

"SD" {

 

 

Sudan

 

HTTP::redirect "http://www.example.com/home-sd"

 

}

 

"SZ" {

 

 

Switzerland

 

HTTP::redirect "http://www.example.com/home-sz"

 

}

 

"SY" {

 

 

Syria

 

HTTP::redirect "http://www.example.com/home-sy"

 

}

 

"TN" {

 

 

Tunisia

 

HTTP::redirect "http://www.example.com/home-tn"

 

}

 

"TR" {

 

 

Turkey

 

HTTP::redirect "http://www.example.com/home-tr"

 

}

 

"UA" {

 

 

Ukraine

 

HTTP::redirect "http://www.example.com/home-ua"

 

}

 

"AE" {

 

 

United Arab Emirates

 

HTTP::redirect "http://www.example.com/home-ae"

 

}

 

"YE" {

 

 

Yemen

 

HTTP::redirect "http://www.example.com/home-ye"

 

}

 

 

"ZZ" {

 

Redirect all others

 

HTTP::redirect "http://www.example.com/home"

 

}

 

}

 

}

 

else {

 

pool example_web_pool

 

}

 

}

 

 

 

 

Regards

 

insitha

 

3 Replies

  • Hi insitha,

    There were a few issues with that iRule:

    The square braces act like backticks in Linux, executing the string within as a command. You had a few two many sets of braces around your commands.

    The URI will always start with "". So that check of the URI would never be false.

    You can combine most of the switch cases into one action where you're redirecting to the country specific URL.

    Lastly you can use the default keyword in the switch case as a catch-all.

    when HTTP_REQUEST {
    
    if { [string tolower [HTTP::host]] equals "www.example.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 {
    "af" -
    "bh" -
    "bd" -
    "be" -
    "eg" -
    "fr" -
    "de" -
    "in" -
    "ir" -
    "iq" -
    "it" -
    "jo" -
    "kz" -
    "ke" -
    "kw" -
    "lb" -
    "mo" -
    "np" -
    "nl" -
    "om" -
    "pk" -
    "qa" -
    "ru" -
    "sa" -
    "es" -
    "lk" -
    "sd" -
    "sz" -
    "sy" -
    "tn" -
    "tr" -
    "ua" -
    "ae" -
    "ye" {
    HTTP::redirect "http://www.example.com/home-${country}"
    } 
    default {
     Redirect all others
    HTTP::redirect "http://www.example.com/home"
    }
    }
    } else {
    pool example_web_pool
    }
    }
    

    Aaron
  • THASIN's avatar
    THASIN
    Icon for Nimbostratus rankNimbostratus
    thanks a lot . it is working fine.

     

    i want to know how to configure dynamic parameter name in ASM policy
  • Hi Thasin,

     

     

    Have you checked the ASM config guide for your version? There is a chapter on working with parameters which includes info on configuring dynamic parameters. Here's an example from 10.2:

     

     

    http://support.f5.com/kb/en-us/products/big-ip_asm/manuals/product/config_guide_asm_10_2_0/asm_parameters.html?sr=187902971043530

     

     

    If you have questions on this, can you post to the Web App Security forum:

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/39/aff/47/showtab/groupforums/Default.aspx

     

     

    Aaron