# Route base on source address

**URL:** <https://community.f5.com/t/route-base-on-source-address/14512>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [May 18, 2007, 6:18pm UTC](https://community.f5.com/t/route-base-on-source-address/14512 "2007-05-18T18:18:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Welson\_Alexandr](https://avatars.discourse-cdn.com/v4/letter/w/d07c76/32.png) [@Welson\_Alexandr](https://community.f5.com/u/Welson_Alexandr)\
**Post date:** [May 18, 2007, 6:18pm UTC](https://community.f5.com/t/route-base-on-source-address/14512/1 "2007-05-18T18:18:53Z")

</div>

This is my first try at iRules.

I would like to route a users to a pool in Data Center 1 if let’s say they are coming from subnet 10.200.0.0 else redirect them to [http://otherurl.com:8080](http://otherurl.com:8080) that is a VIP in Data Center 2

Will this work:

when CLIENT\_ACCEPTED {

if { [IP::addr [IP::client\_addr]/8 equals 10.200.0.0] } {

pool dev\_testpool

} else {

HTTP::redirect “[http://otherurl.com:8080/](http://otherurl.com:8080/)”

}

}

---

<div class="post-metadata">

**Author:** ![Nathan\_McKay\_67](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Nathan\_McKay\_67](https://community.f5.com/u/Nathan_McKay_67)\
**Post date:** [May 18, 2007, 8:12pm UTC](https://community.f5.com/t/route-base-on-source-address/14512/2 "2007-05-18T20:12:31Z")

</div>

You might want to structure this a bit differently and use the matchclass command with an appropriate data group to contain the desired source addresses to match against. Something like:

```tcl
when HTTP_REQUEST {
 if { not [matchclass [ IP::client_addr] equals $::subnet_group ] {
  HTTP::redirect "http://otherurl.com:8080[HTTP::uri]"
  }
 }

```

Then just set the default pool for the VS to dev\_testpool or whatever. This way you execute code to handle the exceptions, can manage stacked iRules a little better, and also redirect them to the URI that was originally requested (if you wanted to do that).
