Forum Discussion

RonR10_181817's avatar
RonR10_181817
Icon for Nimbostratus rankNimbostratus
Jun 10, 2015

iRule Redirection using Switch

Hello all - I am requesting your expertise to determine why this iRule doesn't work 100%. I am trying to redirect users to a page upon entering the site.

1) http://www.site1.com or http://site1.com works correctly and redirects me to the maintenance page. 2) But if I go to http://www.site1.com/MyAccount or http://site1.com/MyAccount, it does NOT redirect me to the maintenance page.

Thanks in advance! Ron

when HTTP_REQUEST {
  if { (([HTTP::host] equals "site1.com") or ([HTTP::host] equals "[www.site1.com](http://www.site1.com)")) }{
    switch -glob [string tolower [HTTP::uri]] {
      "/" -
      "*MyAccount*"
      {
        HTTP::uri "/MaintenancePage.html"
     }
    }
  }
 }

3 Replies

  • Hi,

    you used

    [string tolower [HTTP::uri]]
    - when you use string tolower you should specify the pattern also in lower case e.g. myaccount not MyAccount

    Greets Michael

  • Hi,

    Yes, I agree with Michael.

    But I would change the syntax of the condition, I'm thinking that it is confused and maybe there is a syntax error.
    when HTTP_REQUEST {
        if { [lsearch {"site1.com" "www.site1.com"} [HTTP::host]] != -1 }{
            switch -glob [string tolower [HTTP::uri]] {
                "/" -
                "*myaccount*" {
                    HTTP::uri "/MaintenancePage.html"
                }
            }
        }
    }