Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Oct 05, 2010

Trouble with switch statements and multiple http::host and http::uri

Good morning all,

I've scripted an iRule in hopes of being able to consolidate multiple rules together. This rule is supposed to check the host, check the uri, and evaluate both, and redirect where needed.

The first host check is working fine (events.oursite.com) and redirects fine, however if I try to enter the second host into my browser, I'm simply not being redirected properly. (adifferentsite.com)

I'm stumped, in the meantime I'm going to try and improve on my syntax. Can anyone point me in the right direction as far as where I may be going wrong? Thank you in advance!

Here's the rule:

when HTTP_REQUEST {

switch -glob [string tolower [HTTP::host]] {

"events.oursite.com" {

Check the URI, set to lowercase

switch [string tolower [HTTP::uri]] {

"/eventpage.aspx?event=something08" {

HTTP::redirect "http://redirecteddomain.com"

return

}

}

switch -glob [string tolower [HTTP::host]] {

"adifferentsite.com" {

Check the URI, set to lowercase

switch [string tolower [HTTP::uri]] {

"/presentations*" {

HTTP::redirect "http://some.site.com/information/download-resources.aspx"

return

}

}

}

}

}

}

}

4 Replies

  • No need to have two switch statements checking HTTP::host. You could try something like this:

    
     when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::host]] {
            "events.oursite.com" {
                switch -glob [string tolower [HTTP::uri]] {
                    "/eventpage.aspx?event=something08" {
                        HTTP::redirect "http://redirecteddomain.com"
                    }
                }
    }
            "adifferentsite.com" {
                switch -glob [string tolower [HTTP::uri]] {
                    "/presentations*" {
                        HTTP::redirect "http://some.site.com/information/download-resources.aspx"
                    }
                }
            }
        }
    }
  • Wow - you just saved me from frustration. Thank you for your help, it is much appreciated!
  • Hi Joel,

     

     

    I've modified your script a bit, any idea why the first part of the irule isn't redirecting properly, as if the first part of the irule isn't matching the uri?

     

     

    Correction - I needed to drop the lower case letters - all is well now thank you!