# Region HTTP redirect

**URL:** <https://community.f5.com/t/region-http-redirect/66166>\
**Category:** Community CodeShare\
**Tags:** irules, utility, devops\
**Created:** [March 18, 2015, 9:42pm UTC](https://community.f5.com/t/region-http-redirect/66166 "2015-03-18T21:42:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Bhattman](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/the_bhattman/32/13958_2.png) [@The\_Bhattman](https://community.f5.com/u/The_Bhattman)\
**Post date:** [March 18, 2015, 9:42pm UTC](https://community.f5.com/t/region-http-redirect/66166/1 "2015-03-18T21:42:05Z")

</div>

**Problem this snippet solves:**

The following is an example iRule where you can redirect the same websites across different regions based on the clients IP address.

$::regionXclients is a datagroup that contains network addresses of clients in the region1 which can be any region you wish to base your logic on. $::pool\_regionXservers corresponds with the resource of there the pool of servers

For example: region1clients contain clients in the east coast, region2clients contain clients in the west coast, region3clients contain clients in the Europe and finally region4clients contain clients for asia pacific. pool\_region2servers contain servers for region1clients, pool\_region2server contain servers for region2clients, etc. However, if say pool\_region1servers is down then it will send region1clients over to server to pool\_region2servers and so forth.

**Code :**

```auto
if { ([matchclass [IP::client_addr] eq $::region1clients]) {  
      if { [active_members pool_region1servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region1"
      } else if { [active_members pool_region2servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region2"
      } else if { [active_members pool_region3servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region3"
      } else if { [active_members pool_region4servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region4"
          }  
   } else if { ([matchclass [IP::client_addr] eq $::region2clients]) {
      if { [active_members pool_region2servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region2"
      } else if { [active_members pool_region3servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region3"
      } else if { [active_members pool_region4servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region4"
      } else if { [active_members pool_region1servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region1"
          }
   } else if { ([matchclass [IP::client_addr] eq $::region3clients]) {
      if { [active_members pool_region3servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region3"
      } else if { [active_members pool_region4servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region4"
      } else if { [active_members pool_region1servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region1"
      } else if { [active_members pool_region2servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region2"
          }
   } else if { ([matchclass [IP::client_addr] eq $::region4clients]) {
      if { [active_members pool_region4servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region4"
      } else if { [active_members pool_region1servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region1"
      } else if { [active_members pool_region2servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region2"
      } else if { [active_members pool_region3servers] > 0 } {
          HTTP::redirect "http://[HTTP::host]/region3"
          } 
    }
}

```
