# Combine two iRules

**URL:** <https://community.f5.com/t/combine-two-irules/44259>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [September 15, 2011, 4:33pm UTC](https://community.f5.com/t/combine-two-irules/44259 "2011-09-15T16:33:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TJ\_Vreugdenhil\_1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TJ\_Vreugdenhil\_1](https://community.f5.com/u/TJ_Vreugdenhil_1)\
**Post date:** [September 15, 2011, 4:33pm UTC](https://community.f5.com/t/combine-two-irules/44259/1 "2011-09-15T16:33:11Z")

</div>

Hi - I am trying to combine two iRules on 9.x.

I believe a switch -glob statement would be appropriate, but not sure how do it with two different HTTP::‘operators.’

when HTTP\_REQUEST {

if { !([HTTP::path] equals “[http://test/niku/app](http://test/niku/app)”) } {

HTTP::redirect “[https://test.testmarketing.com](https://test.testmarketing.com)[HTTP::uri]”

}

}

when HTTP\_REQUEST {

if { [HTTP::host] equals “test” } {

HTTP::redirect “[https://test.testmarketing.com](https://test.testmarketing.com)[HTTP::uri]”

}

}

Suggestions?

Thanks!

-TJ

---

<div class="post-metadata">

**Author:** ![Brian\_69413](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@Brian\_69413](https://community.f5.com/u/Brian_69413)\
**Post date:** [September 15, 2011, 4:38pm UTC](https://community.f5.com/t/combine-two-irules/44259/2 "2011-09-15T16:38:28Z")

</div>

I am not sure I follow completely, but it seems to me that this would do the trick:

```tcl
when HTTP_REQUEST {
    if { ([HTTP::host] equals "test") & (!([HTTP::uri] equals "/niku/app")) } {
        HTTP::redirect "https://test.testmarketing.com[HTTP::uri]"
    }
}

```

---

<div class="post-metadata">

**Author:** ![Brian\_69413](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@Brian\_69413](https://community.f5.com/u/Brian_69413)\
**Post date:** [September 15, 2011, 4:42pm UTC](https://community.f5.com/t/combine-two-irules/44259/3 "2011-09-15T16:42:33Z")

</div>

Replace & with && or and

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [September 15, 2011, 4:43pm UTC](https://community.f5.com/t/combine-two-irules/44259/4 "2011-09-15T16:43:35Z")

</div>

i think the 2nd HTTP\_REQUEST is superset of the 1st one.

---

<div class="post-metadata">

**Author:** ![Brian\_69413](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@Brian\_69413](https://community.f5.com/u/Brian_69413)\
**Post date:** [September 15, 2011, 4:59pm UTC](https://community.f5.com/t/combine-two-irules/44259/5 "2011-09-15T16:59:28Z")

</div>

I read the request as “I want to redirect all traffic to this host, except for this one path”

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [September 15, 2011, 5:02pm UTC](https://community.f5.com/t/combine-two-irules/44259/6 "2011-09-15T17:02:37Z")

</div>

I read the request as “I want to redirect all traffic to this host, except for this one path”

thanks. i overlooked not (!) in the question.

---

<div class="post-metadata">

**Author:** ![TJ\_Vreugdenhil\_1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TJ\_Vreugdenhil\_1](https://community.f5.com/u/TJ_Vreugdenhil_1)\
**Post date:** [September 15, 2011, 5:05pm UTC](https://community.f5.com/t/combine-two-irules/44259/7 "2011-09-15T17:05:21Z")

</div>

Sorry for the confusion guys. Let me update some words so that it doesn’t supersede itself.

Brain - I have always wanted some explanation to ‘&&’. This is an ‘or’ statement correct, not an ‘and’ statement, correct?

I’m looking for an ‘OR’

when HTTP\_REQUEST {

if { ([HTTP::host] equals “nice”) && (!([HTTP::uri] equals “/niku/app”)) } {

HTTP::redirect “[https://nice.testmarketing.com](https://nice.testmarketing.com)[HTTP::uri]”

}

}

Thanks!

-TJ

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [September 15, 2011, 5:12pm UTC](https://community.f5.com/t/combine-two-irules/44259/8 "2011-09-15T17:12:31Z")

</div>

pls feel free to revise.

```tcl
[root@orchid:Active] config b virtual bar80 list
virtual bar80 {
   snat automap
   pool foo80
   destination 172.28.17.88:http
   ip protocol tcp
   rules myrule
   profiles
      http
      tcp
}
[root@orchid:Active] config b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   if {[string tolower [HTTP::host]] equals "nice" and [string tolower [HTTP::uri]] ne "/niku/app"} {
      HTTP::redirect "https://nice.testmarketing.com[HTTP::uri]"
   }
}
}

[root@orchid:Active] config curl -I http://nice/niku/app
HTTP/1.1 404 Not Found
Date: Thu, 15 Sep 2011 17:12:10 GMT
Server: Apache/2.0.59 (rPath)
Vary: Accept-Encoding
Content-Type: text/html; charset=iso-8859-1

[root@orchid:Active] config curl -I http://nice/abc
HTTP/1.0 302 Found
Location: https://nice.testmarketing.com/abc
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

```

---

<div class="post-metadata">

**Author:** ![Brian\_69413](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@Brian\_69413](https://community.f5.com/u/Brian_69413)\
**Post date:** [September 15, 2011, 5:28pm UTC](https://community.f5.com/t/combine-two-irules/44259/9 "2011-09-15T17:28:40Z")

</div>

Brian - I have always wanted some explanation to ‘&&’. This is an ‘or’ statement correct, not an ‘and’ statement, correct?

The && is an AND statement and || is an OR statement. If you use an OR the above example, a person going to nice/niku/app will get redirected since it evaluated the left side first.

---

<div class="post-metadata">

**Author:** ![TJ\_Vreugdenhil\_1](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@TJ\_Vreugdenhil\_1](https://community.f5.com/u/TJ_Vreugdenhil_1)\
**Post date:** [September 15, 2011, 5:47pm UTC](https://community.f5.com/t/combine-two-irules/44259/10 "2011-09-15T17:47:12Z")

</div>

Thanks for your help guys. Much appreciated!

-TJ
