John_Giannone_4
Jun 09, 2008Nimbostratus
IRules for Redirection on GTM
We are currently using a GTM 1500 to redirect incoming web traffic based on Geographic locaiton. So when someone comes to our mainsite (for example) and they are from Australia, we serve them the IP of our domain.au site. For this we are using Regions and Topology records. Woroks great.
We want to change to IRules however, so we can redirect customers for several different wide IPs. The IRule we have configued per DEV central is as follows, however, I am told by F5 that it doesnt work and there may be a bug:
when DNS_REQUEST {
if {[whereis [IP::remote_addr]] contains "US"} {
pool raileurope_us_pool
}
if {[whereis [IP::remote_addr]] contains "AU"} {
pool raileurope_au_pool
}
if {[whereis [IP::remote_addr]] contains "JP"} {
pool raileurope_jp_pool
}
if {[whereis [IP::remote_addr]] contains "ZA"} {
pool raileurope_sa_pool
}
if {[whereis [IP::remote_addr]] contains "BO"} {
pool raileurope_bolivia_pool
}
if {[whereis [IP::remote_addr]] contains "CL"} {
pool raileurope_chile_pool
}
if {[whereis [IP::remote_addr]] contains "CO"} {
pool raileurope_columbia_pool
}
if {[whereis [IP::remote_addr]] contains "EC"} {
pool raileurope_ecuador_pool
}
if {[whereis [IP::remote_addr]] contains "PY"} {
pool raileurope_paraguay_pool
}
if {[whereis [IP::remote_addr]] contains "PE"} {
pool raileurope_peru_pool
}
if {[whereis [IP::remote_addr]] contains "UY"} {
pool raileurope_uruguay_pool
}
if {[whereis [IP::remote_addr]] contains "VE"} {
pool raileurope_venezuela_pool
} else {
pool raileurope_us_pool
}
}
I am told by F5 that the following IRule does work. Is there a better way to write it though:
when DNS_REQUEST {
set wherefrom [whereis [IP::remote_addr]]
if {$wherefrom ends_with "US"} {
pool raileurope_us_pool
} elseif {$wherefrom ends_with "AU"} {
pool raileurope_au_pool
} elseif {$wherefrom ends_with "JP"} {
pool raileurope_jp_pool
} elseif {$wherefrom ends_with "ZA"} {
pool raileurope_sa_pool
} elseif {$wherefrom ends_with "BO"} {
pool raileurope_bolivia_pool
} elseif {$wherefrom ends_with "CL"} {
pool raileurope_chile_pool
} elseif {$wherefrom ends_with "CO"} {
pool raileurope_columbia_pool
} elseif {$wherefrom ends_with "EC"} {
pool raileurope_ecuador_pool
} elseif {$wherefrom ends_with "PY"} {
pool raileurope_paraguay_pool
} elseif {$wherefrom ends_with "PE"} {
pool raileurope_peru_pool
} elseif {$wherefrom ends_with "UY"} {
pool raileurope_uruguay_pool
} elseif {$wherefrom ends_with "VE"} {
pool raileurope_venezuela_pool
} else {
pool raileurope_us_pool
}
}