Forum Discussion
url redirect based on Geo location and VIP active
Looking for an iRule for url redirect based on Geo location in LTM and only when VIP active.
- praneshmaniseka
Nimbostratus
I've modified the irule for url redirect based on Geo location by continent. I also need to include this redirect invokes when only the VIP is in active. Let me know how to achieve
when HTTP_REQUEST { if {[HTTP::path] eq “/” } { set client_ip [IP::client_addr] set client_continent [whereis $client_ip continent] if { $client_ip ne “” } { switch [string toupper [whereis $client_ip continent]] { “NA” { HTTP::redirect “http://app-NA.abc.com” } “EU” { HTTP::redirect “http://app-EMEA.abc.com” } “AS” { HTTP::redirect “http://app-APAC.abc.com” } “SA” { HTTP::redirect “http://app-NA.abc.com” } “AF” { HTTP::redirect “http://app-EMEA.abc.com” } “OC” { HTTP::redirect “http://app-APAC.abc.com” } default { HTTP::redirect “http://app-NA.abc.com” } } } }
- Lee_Sutcliffe
Nacreous
Virtual Server status is returned from the pool status that is associated to the VS. So you could nest an if condition checking the pool for each VS before redirecting:
eg:
. . switch [whereis [IP::client_addr] continent] { “NA” { if { [active_members my_NA_pool] < 1 } { HTTP::redirect “http://app-NA.abc.com” } . .
- Lee_Sutcliffe
Nacreous
Ok, so I've taken another look at this as sounds like you want to have a default redirect in the event the pool member (and therefore the VIP is down). It was starting to get messy with nested 'if' statements within the switch. Also there was a lot of repetition so thought using a loop may be better, rather than adding more conditions.
I've put your redirects and pool details for each region in a datagroup and added them to an array so that the variable can be used in the loop. I've tested the syntax but not the functionality
Please leave feedback
DATAGROUP:
ltm data-group internal geo_dg { records { NA { data "POOL my_NA_pool|URL http://app-NA.abc.com" } EU { data "POOL my_EU_pool|URL http://app-EMEA.abc.com" } AS { data "POOL my_AS_pool|URL http://app-APAC.abc.com" } SA { data "POOL my_SA_pool|URL http://app-NA.abc.com" } AF { data "POOL my_AF_pool|URL http://app-EMEA.abc.com" } OC { data "POOL my_AF_pool|URL http://app-APAC.abc.com" } } type string }
IRULE:
when HTTP_REQUEST { set dgLocation geo_dg set regions {NA EU AS SA AF OC} set ipLocation [whereis [IP::client_addr] continent] set defaultRedirect "http://app-NA.abc.com" if {[HTTP::path] eq "/" } { check GeoLocation matches what is defined in the datagroup if {[class match $ipLocation equals $dgLocation]} { loop through the regions in the list foreach region $regions { create array based on DG values array set geoArray [split [string trim [class lookup $region $poolDg]] "|"] check for active members if { [active_members $geoArray(POOL)] >= 1 } { HTTP::redirect $geoArray(URL) } else { default redirect if pool is down HTTP::redirect $defaultRedirect } array unset geoArray } } else { default redirect if GeoLocation doesn't match datagroup HTTP::redirect $defaultRedirect } } }
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com