Forum Discussion
missing close-brace issue - iRule newbie
Hi,
I'm developing an iRule that will stop redirect users if they hit a specific URI, I'm needing to put this in the top of my current iRule so that it captures the request at the top to capture the client in the first instance.
I've masked the corporate information, can anyone help with this? I've included the iRule and error message.
I'm pretty new to iRules so still getting used to syntax etc (new to scripting/programming too) since I am a network engieer.
when HTTP_REQUEST {
set requestedHost [HTTP::host]
if { ([HTTP::uri] starts_with "/URI1") || ([HTTP::uri] starts_with "/URI2") || ([HTTP::uri] starts_with "/URI3") || ([HTTP:uri] starts_with "/URI4") || ([HTTP::uri] starts_with "/URI5") || ([HTTP::uri] starts_with "/URI6")}
Static content is available on paths beginning /web and should be routed to a specific pool
if { [HTTP::uri] starts_with "/web" } {
if { [active_members hda_twss_web_pool] < 1 } {
log local0. "No pool member a available in hda_twss_web_pool"
HTTP::redirect "http://www.wheatly-group.com"
return
} else {
pool hda_twss_web_pool
log local0. "Sending to pool hda_twss_web_pool"
return
}
} elseif { not( [HTTP::uri] starts_with "/path/" ) } {
Application Content
Rewrite the uri based on a host match
switch [HTTP::host] {
"t-my.site.org" {
HTTP::uri "/path/to/features/AAtheme[HTTP::uri]"
}
"t-my.site2.org" {
HTTP::uri "/path/to/features/BBtheme[HTTP::uri]"
}
"t-my.site3.org" {
HTTP::uri "/path/to/features/CCtheme[HTTP::uri]"
}
"t-my.site4.org" {
HTTP::uri "/path/to/features/DDtheme[HTTP::uri]"
}
"t-my.site5.org" {
HTTP::uri "/path/to/features/EEtheme[HTTP::uri]"
}
"t-my.site6.org" {
HTTP::uri "/path/to/features/FFtheme[HTTP::uri]"
}
}
pool hda_twss_web_pool
log local0. "URI rewrite to HTTP::uri"
}
{
when HTTP_RESPONSE {
if { [HTTP::cookie exists "JSESSIONID"] } {
HTTP::cookie domain JSESSIONID "$requestedHost"
HTTP::cookie path JSESSIONID "/"
}
}
And here is the error message - I've had to truncate some details within this also:
01070151:3: Rule [/Common/hda_uri_test] error: /Common/hda_uri_test:1: error: [parse error: missing close-brace][{
set requestedHost [HTTP::host]
Thanks for your time,
Tam.
4 Replies
- iaine
Nacreous
Hi
If you look at the line above HTTP_RESPONSE, you have an open bracket, i suspect that this should be a close bracket.
BTW - I use Notepad++ for bracket counting when writing iRules as it shows the open and corresponding close bracket in red - it then soon becomes obvious when you have a mis-match
- iaine
Nacreous
It also looks like you are missing an open { at the end of you opening if statement and the a corresponding close. Also, you've missed a : from a HTTP::uri. The code below should now hopefully save.
when HTTP_REQUEST { set requestedHost [HTTP::host] if { ([HTTP::uri] starts_with "/URI1") || ([HTTP::uri] starts_with "/URI2") || ([HTTP::uri] starts_with "/URI3") || ([HTTP::uri] starts_with "/URI4") || ([HTTP::uri] starts_with "/URI5") || ([HTTP::uri] starts_with "/URI6")} { Static content is available on paths beginning /web and should be routed to a specific pool if { [HTTP::uri] starts_with "/web" } { if { [active_members hda_twss_web_pool] < 1 } { log local0. "No pool member a available in hda_twss_web_pool" HTTP::redirect "http://www.wheatly-group.com" return } else { pool hda_twss_web_pool log local0. "Sending to pool hda_twss_web_pool" return } } elseif { not( [HTTP::uri] starts_with "/path/" ) } { Application Content Rewrite the uri based on a host match switch [HTTP::host] { "t-my.site.org" { HTTP::uri "/path/to/features/AAtheme[HTTP::uri]" } "t-my.site2.org" { HTTP::uri "/path/to/features/BBtheme[HTTP::uri]" } "t-my.site3.org" { HTTP::uri "/path/to/features/CCtheme[HTTP::uri]" } "t-my.site4.org" { HTTP::uri "/path/to/features/DDtheme[HTTP::uri]" } "t-my.site5.org" { HTTP::uri "/path/to/features/EEtheme[HTTP::uri]" } "t-my.site6.org" { HTTP::uri "/path/to/features/FFtheme[HTTP::uri]" } } pool hda_twss_web_pool log local0. "URI rewrite to HTTP::uri" } } } when HTTP_RESPONSE { if { [HTTP::cookie exists "JSESSIONID"] } { HTTP::cookie domain JSESSIONID "$requestedHost" HTTP::cookie path JSESSIONID "/" } } - Thomas_McLean_1
Nimbostratus
I have resolved this. I had two issues a missing : within a HTTP::uri and also didn't have the HTTP::respond 301 Location with the redirect URL.
Thanks for looking everyone. The solution is below:
if { ([HTTP::uri] starts_with "/URI1") || ([HTTP::uri] starts_with "/URI2") || ([HTTP::uri] starts_with "/URI3") || ([HTTP:uri] starts_with "/URI4") || ([HTTP::uri] starts_with "/URI5") || ([HTTP::uri] starts_with "/URI6")} HTTP::respond 301 Location "http://google.com/" - Thomas_McLean_1
Nimbostratus
Thanks for the tips guys, still learning and my eyes are going square when looking at the command syntax...picking it up slowly and really liking the flexible approach that we can utilise when something is required!
Cheers,
Tam.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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