# Redirect request using multiple conditions

**URL:** <https://community.f5.com/t/redirect-request-using-multiple-conditions/37910>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [September 23, 2008, 2:13pm UTC](https://community.f5.com/t/redirect-request-using-multiple-conditions/37910 "2008-09-23T14:13:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![szia\_80879](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@szia\_80879](https://community.f5.com/u/szia_80879)\
**Post date:** [September 23, 2008, 2:13pm UTC](https://community.f5.com/t/redirect-request-using-multiple-conditions/37910/1 "2008-09-23T14:13:05Z")

</div>

Hello everyone,

I am having trouble making an iRule works. I could not figure out what is causing this issue. Let me explain what I want to accomplish with the iRule.

I have two URIs: “/” is for external users and “/xyz” for internal users. I want to use two conditions to separate the external request from internal request.

First condition: Users are allow to use either [HTTP::host/] or [HTTP::host]/xyz

Second condition: User will be redirected to external or internal site based on their source addresses.

I wrote a test iRule. It works only for the external URI. It does not work for internal URI and creates a loop. My Big-IP log file is getting hammered with these loop entries when I tested. Please help me to find what is in the iRule is causing this loop. Any help will be appreciated. Thank you in advance.

when HTTP\_REQUEST {

if { [HTTP::uri] equals “/” or ([HTTP::uri] ends\_with “/xyz”)} {

if { [matchclass [IP::client\_addr] equals $::restricted\_client\_datagroup]} {

HTTP::redirect http://[HTTP::host]/xyz

}

pool Corporate\_8080\_Pool

} else {

if { not [matchclass [IP::client\_addr] equals $::restricted\_client\_datagroup]} {

HTTP::redirect http://[HTTP::host]/

}

pool Corporate\_8080\_Pool

}

log the client IP address → destination IP address

log local0. "request accepted from client: \

[IP::client\_addr] → [IP::local\_addr] → [HTTP::uri]"

}

---

<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:** [September 23, 2008, 10:50pm UTC](https://community.f5.com/t/redirect-request-using-multiple-conditions/37910/2 "2008-09-23T22:50:45Z")

</div>

I think I see what’s happening in your code.

Try the following:

```tcl
when HTTP_REQUEST { 
 if { ([HTTP::uri ends_with "/") or ([HTTP::uri] ends_with "/xyx")} { 
 if {[matchclass [IP::client_addr] == $::restricted_cleint_datagroup]} { 
 HTTP::redirect http://[HTTP::host]/xyz 
 pool Corporate_8080_Pool 
 } else {  
 HTTP::redirect http://[HTTP::host]/ 
 pool Corporate_8080_Pool 
 } 
 } 
 log local0. "request accepted from client: [IP::client_addr] -> [IP::local_addr] -> [HTTP::uri]"  
 }

```

Hope this helps

CB

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 24, 2008, 3:42pm UTC](https://community.f5.com/t/redirect-request-using-multiple-conditions/37910/3 "2008-09-24T15:42:27Z")

</div>

Do you want to rewrite the URI inline and send the request to the pool? If so, change HTTP::redirect to HTTP::uri in CB’s example.

I think the original issue was that you were redirecting clients show requested /xyz and were part of the restricted\_client\_datagroup class endlessly.

Aaron

---

<div class="post-metadata">

**Author:** ![szia\_80879](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@szia\_80879](https://community.f5.com/u/szia_80879)\
**Post date:** [September 25, 2008, 3:42pm UTC](https://community.f5.com/t/redirect-request-using-multiple-conditions/37910/4 "2008-09-25T15:42:50Z")

</div>

Thank you both CB and Aaron. Your input helped me to fix the problem. Thank you again.
