# return and HTTP::redirect usage

**URL:** <https://community.f5.com/t/return-and-http-redirect-usage/39362>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [May 12, 2011, 9:08am UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362 "2011-05-12T09:08:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [May 12, 2011, 9:08am UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/1 "2011-05-12T09:08:31Z")

</div>

Hi,I have a irule like this

if {$uri matches\_regex “^/(help/)”}

{

HTTP::redirect ]

pool cjj1

return

}

else{

pool cjj2

}

1:don’t know the true meaning of return

2:can I use

HTTP::redirect http://[HTTP::HOST][HTTP::uri]

pool cjj1

in this way?

---

<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:** [May 12, 2011, 2:41pm UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/2 "2011-05-12T14:41:00Z")

</div>

Hi Jucao,

Return immediately exits the current EVENT. In your case if there is a match for “cjj1” it exits the event and does not further process the statement. From your posting it appears that you do not need a return statement.

I hope this helps

Bhattman

---

<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 12, 2011, 5:03pm UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/3 "2011-05-12T17:03:32Z")

</div>

I’d also replace the regex with a more efficient string command:

if {$uri starts\_with “/help/”}

As Bhattman said, you don’t need the return statement unless you have more code after the else statement.

Aaron

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [May 13, 2011, 3:20am UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/4 "2011-05-13T03:20:08Z")

</div>

Hi,Bhattman hoolio

Thanks for your help

if there exist 2 events in this irule ,

when HTTP::request

if {$uri matches\_regex “^/(help/)”}

{

HTTP::redirect http://[HTTP::HOST][HTTP::uri]

pool cjj1

return

}

else{

pool cjj2

}

when client::accpt

{

xxxxxx

}

1:if I want the traffic jump out of the irule when match help,it make sense to use return ,right?

if only one event here,it is no need to use return ,right?

2:I want to change the url to http://[HTTP::HOST][HTTP::uri] and send it to pool cjj1

does it work in my irule ?

if {$uri matches\_regex “^/(help/)”}

{

HTTP::redirect http://[HTTP::HOST][HTTP::uri]

pool cjj1

return

}

else{

pool cjj2

}

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [May 16, 2011, 9:04am UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/5 "2011-05-16T09:04:37Z")

</div>

Hi,can some one help me ?

---

<div class="post-metadata">

**Author:** ![richard\_77048](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@richard\_77048](https://community.f5.com/u/richard_77048)\
**Post date:** [May 16, 2011, 12:55pm UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/6 "2011-05-16T12:55:48Z")

</div>

The HTTP::redirect command immediately sends the redirect response to the client. You can’t set a pool after issuing this command. You are sending the client back through your loadbalancer on a new request.

Also, if $uri = [HTTP:uri], then you will be in a redirect loop since you are not altering the client request when you redirect them. If $uri != [HTTP::uri], then you need an “elseif” clause that catches the new request and uses pool cjj1.

So, like this:

when HTTP\_REQUEST {

if { $uri starts\_with “/help/” } {

HTTP::redirect “http://[HTTP::host][HTTP::uri]”

}

elseif { some new condition that matches your redirected request } {

pool cjj1

}

else {

pool cjj2

}

}

I haven’t used “return” so I won’t advise on its use.

Richard

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [May 17, 2011, 1:23am UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/7 "2011-05-17T01:23:04Z")

</div>

thank richard so much

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [May 17, 2011, 4:09pm UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/8 "2011-05-17T16:09:57Z")

</div>

Keep in mind that return does not exit the iRule, only the event context that it’s fired in. This means in an iRule with multiple events, return does **not** stop the rest of the events from processing. It merely stops the processing of the current event.

Colin

---

<div class="post-metadata">

**Author:** ![richard\_77048](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@richard\_77048](https://community.f5.com/u/richard_77048)\
**Post date:** [May 17, 2011, 4:57pm UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/9 "2011-05-17T16:57:03Z")

</div>

Colin,

That’s really good to know. So, if you wanted to bail on the rule altogether, would something like this work?

when HTTP\_REQUEST {

if { some\_condition } {

set bail\_on\_rule “true”

}

}

when HTTP\_RESPONSE {

if { $bail\_on\_rule equals “true” } {

event disable

}

else {

other\_stuff

}

}

Do variables live between events in the same rule? Is there an easier (maybe built in) way of doing this?

Richard

edit: lost my psuedo-code on posting

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [May 17, 2011, 4:59pm UTC](https://community.f5.com/t/return-and-http-redirect-usage/39362/10 "2011-05-17T16:59:25Z")

</div>

There isn’t a way to stop the iRule processing as a whole, really. The closest you can come is “event disable all”, but that’s scoped to the connection as a context. That means that if you fire an event disable (or an event disable all) you’re turning off that event for all iRules on that connection, not just the iRule it was fired within.

There are some logic tricks you can play with things like an info exists at the top of every event in an iRule that will make it behave the way you want, but there isn’t a specific command that exits the iRule.

Colin
