Forum Discussion
Wes_98712
Nimbostratus
Nov 09, 2005undefined procedure: elseif
Ok,
This conversion process is killing me, I almost had a good chunk of my v4.X converted, and working (meaning my 3400 series LB wasn't rebooting...good thing). Now I have a strange issue, by adding the last line in the following code I get the following error:
01070151:3: Rule [r_wes_test] error:
line 27: [undefined procedure: elseif] [elseif { $my_uri starts_with "/worldseries"} { HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/worldseries/index.tbapp?affiliate_id=1b" }]
Here are my irules as of now:
set my_uri [HTTP::uri]
set my_query [HTTP::query]
if { [HTTP::host] equals "soaringdreams.ameriquest.com"} {
HTTP::respond 301 "Location" "http://www.ameriquestsoaringdreams.com"
}
elseif { $my_uri contains "texas" } {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=texasfair"
}
elseif { $my_uri matches_regex "cfide" } {
discard
}
elseif { $my_uri starts_with "/Amigo"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?lang=es&ad=LMAMIGO"
}
elseif { $my_uri starts_with "/LuisMiguelFriend"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?ad=LMFRIEND"
}
elseif { $my_uri contains "directmerchantsbank"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=directmerchantsbank"
}
elseif { $my_uri starts_with "/refi"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=SHAPEMAIL001"
}
elseif { $my_uri starts_with "/freedom"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=SHAPEMAIL002"
}
elseif { $my_uri contains "propertyvalue"} {
HTTP::respond 301 "Location" "http://homevalue.ameriquest.com/fares.html?ad=propertyvalue"
}
elseif { $my_uri contains "espanol"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=espanol"
}
elseif { $my_uri contains "bonuspack"} {
HTTP::respond 301 "Location" "http://homevalue.ameriquest.com/fares.html?ad=bonuspak"
}
elseif { $my_uri contains "bonuspak"} {
HTTP::respond 301 "Location" "http://homevalue.ameriquest.com/fares.html?ad=bonuspak"
}
elseif { $my_uri contains "prime"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/disclaimers/bedford.html"
}
elseif { $my_uri contains "woody"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/welcome.html?ad=woody"
}
elseif { $my_uri starts_with "/house"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/wwwmodules/house.html"
}
elseif { $my_uri contains "freepayments"} {
HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house2005/english/index.tbapp?pic=h"
}
elseif { $my_uri contains "baseball"} {
HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house/?pic=d"
}
elseif { $my_uri starts_with "/freehousepayments"} {
HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house2005/english/index.tbapp?pic=h"
}
elseif { $my_uri contains "monster"} {
HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house/?pic=m"
}
elseif { $my_uri contains "careers"} {
HTTP::respond 301 "Location" "http://careers.ameriquest.com"
}
elseif { $my_uri contains "subsection=welcome&ad="} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/welcome.html?$my_query"
}
elseif { $my_uri starts_with "/creditreport"} {
HTTP::respond 301 "Location" "http://www.onlinecreditinformation.biz/?website=amc"
}
elseif { $my_uri starts_with "/dothemath"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=infom001"
}
I thought that perhaps the TCL implementation has some aversions to white spaces, but if I remove the /worldseries statement it takes the rule just fine, if I move the /worldseries statement behind the /dothemath statement, as follows:
elseif { $my_uri starts_with "/dothemath"} {
HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=infom001"
} elseif { $my_uri starts_with "/worldseries"} {
HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/worldseries/index.tbapp?affiliate_id=1b"
}
it takes it, if I try to keep the formatting the same it throws an exception. I have no friggen clue why. Thoughts?
-Wes
- Wes_98712
Nimbostratus
FYI: If anyone is interested I fixed this by reformatting the code as follows:when HTTP_REQUEST { set my_uri [HTTP::uri] set my_query [HTTP::query] if { [HTTP::host] equals "soaringdreams.ameriquest.com"} { HTTP::respond 301 "Location" "http://www.ameriquestsoaringdreams.com" } elseif { $my_uri contains "texas" } { HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=texasfair" } elseif { $my_uri matches_regex "cfide" } { discard } elseif { $my_uri starts_with "/Amigo"} { HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?lang=es&ad=LMAMIGO" } elseif { $my_uri starts_with "/LuisMiguelFriend"} { HTTP::respond } }
- This is a common issue that seems to crop up every so often. Actually, TCL forces elseif's to be on the same line as the closing brace and the opening brace after it has to be on the same line as well. We've made some changes to the TCL interpreter to allow newlines but there is a bug that you can't have whitespace after the brace and before the newline. I believe this has been fixed in the latest release.
if { condition } { ... } elseif { condition } { ... } else { ... }
when HTTP_REQUEST { set my_uri [HTTP::uri] set my_query [HTTP::query] if { [HTTP::host] equals "soaringdreams.ameriquest.com"} { HTTP::respond 301 "Location" "http://www.ameriquestsoaringdreams.com" } elseif { $my_uri contains "texas" } { HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=texasfair" } elseif { $my_uri contains "cfide" } { discard } elseif { $my_uri starts_with "/Amigo"} { HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?lang=es&ad=LMAMIGO" } elseif { $my_uri starts_with "/LuisMiguelFriend"} { HTTP::respond } }
- Wes_98712
Nimbostratus
Thanks Joe, that worked perfectly. - unRuleY_95363Historic F5 AccountThere's two options for dealing with case. The first is to simply convert the uri either to all lower case or all upper case with the "string tolower" or "string toupper" commands. The second option is to use "string first -nocase" which searches for the first occurence of a string within a string without regard to case.
- Wes_98712
Nimbostratus
Interesting, then I will try the string tolower and see how it works. Thanks. Is there an updated irules PDF that I can reference, I'm finding the one I have for v9 is not accurate at all. - Wes_98712
Nimbostratus
I tried the following and it skips the rule completley, doesn't even log anything:} elseif { [string tolower [HTTP::uri]] contains "StonesReg"} { log local0. HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/wwwmodules/stonessweeps.html?ad=1K" }
set my_uri [HTTP::uri] if { [string tolower $my_uri] contains "StonesReg"} { log local0. HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/wwwmodules/stonessweeps.html?ad=1K" }
- You are converting the URI to lowercase, but then doing a case-comparison with a mixed case string so of course it will never match. Try comparing to a all lowercase string (ie. "StonesReg" => "stonesreg").
- unRuleY_95363Historic F5 AccountUm, I hate to point out the obvious, but "StonesReg" is upper and lowercase. The "string tolower" command converts the uri to all lowercase. Try "stonesreg" as the string you are comparing to...
- Wes_98712
Nimbostratus
Yeah I just figured that out, stupid, stupid stupid...I can't believe I didn't address that before posting. ;-)
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects