# Help

**URL:** <https://community.f5.com/t/help/36783>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [May 5, 2010, 7:39am UTC](https://community.f5.com/t/help/36783 "2010-05-05T07:39:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ido\_Katz\_38061](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@Ido\_Katz\_38061](https://community.f5.com/u/Ido_Katz_38061)\
**Post date:** [May 5, 2010, 7:39am UTC](https://community.f5.com/t/help/36783/1 "2010-05-05T07:39:50Z")

</div>

Hi Guys,

1st of all I want to tell you that you got great community, you doing a great job!

2nd of all…I have a little problem that I’m sure that one of you can help me, I can’t save the IRule because i’m getting confused with the braces.

The IRule going like that:

when HTTP\_REQUEST {

if {[HTTP::header exists “subscriberID”]}

if {[matchclass [HTTP::header “subscriberID”] equals $::subscriberID]}

{pool AA-BB-Pool}

else { HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” )

elseif {[matchclass [IP::client\_addr] equals $::GGG]}

{ log local0. “Valid Source IP: [IP::client\_addr] - forwarding traffic”

pool AA-BB-Pool}

else { HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” } log local0. “INVALID Source IP: [IP::client\_addr] - dropping traffic”

Can someone please help me?

Thanks

Ido

---

<div class="post-metadata">

**Author:** ![Cspillane\_18296](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Cspillane\_18296](https://community.f5.com/u/Cspillane_18296)\
**Post date:** [May 5, 2010, 10:57am UTC](https://community.f5.com/t/help/36783/2 "2010-05-05T10:57:24Z")

</div>

Hello Ido, try this I think it’ll work (at least the iRule editor gives me no complaints!!):

when HTTP\_REQUEST {

if { [matchclass [HTTP::header “subscriberID”] equals $::subscriberID]} {

{pool AA-BB-Pool}

else { HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” target=“\_blank” rel=“nofollow”\>[http://XYZ.com](http://XYZ.com)" )

elseif {[matchclass [IP::client\_addr] equals $::GGG]}

log local0. “Valid Source IP: [IP::client\_addr] - forwarding traffic”

pool AA-BB-Pool}

else { HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” target=“\_blank” rel=“nofollow”\>[http://XYZ.com](http://XYZ.com)" } log local0. “INVALID Source IP: [IP::client\_addr] - dropping traffic”

}

}

However, I don’t think you needed the first ‘if’ statement so I have removed it if {[HTTP::header exists “subscriberID”]} although one of the more experienced chaps may be able to guide you better on that. Let us know how you get on.

---

<div class="post-metadata">

**Author:** ![Ido\_Katz\_38061](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@Ido\_Katz\_38061](https://community.f5.com/u/Ido_Katz_38061)\
**Post date:** [May 5, 2010, 11:13am UTC](https://community.f5.com/t/help/36783/3 "2010-05-05T11:13:28Z")

</div>

Hi There,

I have been told that I have to put this line in the begining,could someone please advise with the 1st line?

Thanks a lot for your help

Ido

---------------------------------------------------------------------------------------------------------

I tryied this one:

when HTTP\_REQUEST {

if [HTTP::header exists “subscriberID”] } {

if [matchclass [HTTP::header “subscriberID”] equals $::subscriberID]} {

pool AA-BB-Pool} {

else {HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” }

elseif { [matchclass [IP::client\_addr] equals $::XXX] } {

log local0. “Valid Source IP: [IP::client\_addr] - forwarding traffic”

pool AA-BB-Pool} {

else { HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” }

log local0. “INVALID Source IP: [IP::client\_addr] - dropping traffic” }

But I can’t save it because of brace’s problem.

Thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![Cspillane\_18296](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Cspillane\_18296](https://community.f5.com/u/Cspillane_18296)\
**Post date:** [May 5, 2010, 2:52pm UTC](https://community.f5.com/t/help/36783/4 "2010-05-05T14:52:14Z")

</div>

Hi Ido,

the following is a valid rule, does this achieve your requirements?

when HTTP\_REQUEST {

if { [matchclass [HTTP::header exists “subscriberID”] equals $::subscriberID] } {

pool AA-BB-Pool

} elseif { [matchclass [IP::client\_addr] equals $::XXX] } {

log local0. “Valid Source IP: [IP::client\_addr] - forwarding traffic”

pool AA-BB-Pool

} else { HTTP::respond 301 Location “[http://XYZ.com](http://XYZ.com)” }

log local0. “INVALID Source IP: [IP::client\_addr] - dropping traffic” }

I am afraid that I have little experience in the use of classes, but to my eye this looks like it should do the job - I’m sure someone will correct my inaccuracies!

As you can see i have removed a couple of lines in an effort to make the rule more efficient (the http::respond command is surely only needed if we don’t match the class for the subscriberID or the valid source IP?).

Thanks and good luck in your testing.

---

<div class="post-metadata">

**Author:** ![Ido\_Katz\_38061](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@Ido\_Katz\_38061](https://community.f5.com/u/Ido_Katz_38061)\
**Post date:** [May 5, 2010, 3:09pm UTC](https://community.f5.com/t/help/36783/5 "2010-05-05T15:09:21Z")

</div>

Please try to keep the stracture as it is, I need this Irule to be as I wrote.

Can you please help me?

I’m sorry for sounding bad and a pain in the ass.

But I really need it to work as it is.

Thanks

Ido

---

<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:** [May 6, 2010, 8:32am UTC](https://community.f5.com/t/help/36783/6 "2010-05-06T08:32:56Z")

</div>

Maybe something like this?

```tcl
when HTTP_REQUEST {
   if {[HTTP::header exists "subscriberID"]}{
      if {[matchclass [HTTP::header "subscriberID"] equals $::subscriberID]}{
         pool AA-BB-Pool
      } else {
         HTTP::respond 301 Location "http://XYZ.com"
      }
   } elseif {[matchclass [IP::client_addr] equals $::XXX]}{
      log local0. "Valid Source IP: [IP::client_addr] - forwarding traffic"
      pool AA-BB-Pool
   } else {
      HTTP::respond 301 Location "http://XYZ.com"
      log local0. "INVALID Source IP: [IP::client_addr] - dropping traffic"
   }
}

```

Note that you can use [code] [/code] tags (without the spaces) to preserve the indentation of your rule code. This makes it a lot easier to see the nesting of braces.

Aaron
