# HTTP\_REQUEST & if, elseif, else statements

**URL:** <https://community.f5.com/t/http-request-if-elseif-else-statements/47494>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [August 17, 2006, 4:05pm UTC](https://community.f5.com/t/http-request-if-elseif-else-statements/47494 "2006-08-17T16:05:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Brandl\_9318](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@Tom\_Brandl\_9318](https://community.f5.com/u/Tom_Brandl_9318)\
**Post date:** [August 17, 2006, 4:05pm UTC](https://community.f5.com/t/http-request-if-elseif-else-statements/47494/1 "2006-08-17T16:05:05Z")

</div>

Hello,

I am trying to consolidate multiple redirection rules with if, elseif, else statements. I’ve researched various posts in the forum and still can’t seem to get the syntax correct. Any assistance would be greatly appreciated. Here’s my script:

when HTTP\_REQUEST {

set host [string tolower [HTTP::host]]

if {$host contains “2006wec”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/wec2006/wechomepage.aspx?id=4829”

} elseif {$host contains “institutes”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/Inst2006/inst06\_template.aspx?id=5935”

} elseif {$host contains “cmm”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/cmm2006/cmm06\_template.aspx?id=5794”

} else {$host contains “wli”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/mpicontent.aspx?id=1210”

}

}

This is the error condition that I receive:

01070151:3: Rule [redirect\_subdomain\_rule] error:

line 7: [deprecated usage, use else or elseif] []

line 3: [undefined procedure:

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/cmm2006/cmm06\_template.aspx?id=5794”

] [if {$host contains “2006wec”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/wec2006/wechomepage.aspx?id=4829”

} elseif {$host contains “institutes”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/Inst2006/inst06\_template.aspx?id=5935”

} else {$host contains “cmm”} {

HTTP::redirect “http://[HTTP::host]/cms/mpiweb/cmm2006/cmm06\_template.aspx?id=5794”

}]

---

<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:** [August 17, 2006, 4:48pm UTC](https://community.f5.com/t/http-request-if-elseif-else-statements/47494/2 "2006-08-17T16:48:19Z")

</div>

I think it’s the last test with else. The else should not be conditional, so either use elseif again, or remove the {$host contains “cmm”} part.

Aaron

---

<div class="post-metadata">

**Author:** ![Tom\_Brandl\_9318](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@Tom\_Brandl\_9318](https://community.f5.com/u/Tom_Brandl_9318)\
**Post date:** [August 17, 2006, 8:32pm UTC](https://community.f5.com/t/http-request-if-elseif-else-statements/47494/3 "2006-08-17T20:32:52Z")

</div>

Hoolio - thanks a million. It was the last conditional statement - replaced with elseif and it works like a champ!
