Forum Discussion
Redirect iRule with URI redirection and pool distribution
Hi,
I have an iRule that redirects URI containing certain syntax. I want to add a switch -glob statement so that the group of URI's that 'starts_with' the /page1, /page2, on so forth gets sent to a certain pool else defaults to pool green. I put in:
Code
switch -glob [HTTP::uri] starts_withBut that statement above returns me errors. I assume that can't be done or has to be done in some other format? Any help is greatly appreciated. Here's my existing code:
Code
when HTTP_REQUEST {
if {[HTTP::uri] contains "/read.pdf"} {
HTTP::redirect "https://www.main.com/menu" }
if {[HTTP::uri] starts_with "/Mypersonal/formula"} {
HTTP::respond 301 Location "https://www.main.com/colors.html" }
switch -glob [HTTP::uri] {
"/page1" -
"/page2" -
"/page3" -
"/index" -
"/start" { pool orange }
default { pool green }
}
}
Code3 Replies
- Kevin_Stewart
Employee
Please try this:
when HTTP_REQUEST { if { [HTTP::uri] contains "/read.pdf" } { HTTP::redirect "https://www.main.com/menu" } elseif { [HTTP::uri] starts_with "/Mypersonal/formula" } { HTTP::respond 301 Location "https://www.main.com/colors.html" } else { switch -glob [HTTP::uri] { "/page1*" - "/page2*" - "/page3*" - "/index*" - "/start*" { pool orange } default { pool green } } }The -glob option allows you to use wildcards in the conditions, so a "starts_with" in a switch -glob would be a URI followed by a start "*".
- TNY_122436
Nimbostratus
Seems like there might be a syntax somewhere that is causing error when I compile the iRule. This is the error I get:
Code 01070151:3: Rule [/Common/test_redierct] error: line 1: [parse error: missing close-brace] [{ if { [HTTP::uri] contains "/read.pdf" } { HTTP::redirect "https://www.main.com/menu" } elseif { [HTTP::uri] starts_with "/Mypersonal/formula" } { HTTP::respond 301 Location "https://www.main.com/colors.html" } else { switch -glob [HTTP::uri] { "/page1*" - "/page2*" - "/page3*" - "/index*" - "/start*" { pool orange } default { pool green } } }] line 2: [command is not valid in the current scope] [if { [HTTP::uri] contains "/read.pdf" } { HTTP::redirect "https://www.main.com/menu" } elseif { [HTTP::uri] starts_with "/Mypersonal/formula" } { HTTP::respond 301 Location "https://www.main.com/colors.html" } else { switch -glob [HTTP::uri] { "/page1*" - "/page2*" - - Kevin_Stewart
Employee
There is in fact a missing closing brace.
when HTTP_REQUEST { if { [HTTP::uri] contains "/read.pdf" } { HTTP::redirect "https://www.main.com/menu" } elseif { [HTTP::uri] starts_with "/Mypersonal/formula" } { HTTP::respond 301 Location "https://www.main.com/colors.html" } else { switch -glob [HTTP::uri] { "/page1*" - "/page2*" - "/page3*" - "/index*" - "/start*" { pool orange } default { pool green } } } }
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