Forum Discussion

Nick_Coelho_338's avatar
Nick_Coelho_338
Icon for Nimbostratus rankNimbostratus
Mar 03, 2007

iRule works but getting browser error, help!

need an iRule that looks for trafficui and gives pool but if it does not see trafficui it looks for the hostname and redirects

 

 

it seems to work but i get errors on the "test1.com" links. better way to do this?

 

 

thanks for any help

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/TrafficUI" } {

 

pool Testy

 

}

 

elseif { [HTTP::host] starts_with "test1" } {

 

HTTP::redirect "http://www.test1.com/TrafficUI/mscui/page.aspx?cid=1&ptid=5"

 

}

 

elseif { [HTTP::host] starts_with "www.test1" } {

 

HTTP::redirect "http://www.test1.com/TrafficUI//mscui/page.aspx?cid=1&ptid=5"

 

}

 

elseif { [HTTP::host] starts_with "test2" } {

 

HTTP::redirect "http://www.test2.com/TrafficUI/mscui/page.aspx?cid=1&ptid=10"

 

}

 

elseif { [HTTP::host] starts_with "www.test2" } {

 

HTTP::redirect "http://www.test2.com/TrafficUI//mscui/page.aspx?cid=1&ptid=10"

 

}

 

elseif { [HTTP::host] starts_with "test" } {

 

HTTP::redirect "http://www.google.com/"

 

}

 

}

5 Replies

  • At first glance, it looks good to me (besides the double slash in the "www.test1" and www.test2 redirects - unless this is what you intended). What kind of errors are you getting?

    Here's an example of using a switch statement for your reference (with test1* and www.test1* redirecting to the same uri).

    when HTTP_REQUEST {
      if { [HTTP::uri] starts_with "/TrafficUI" } {
        pool Testy
      } else {
        switch -glob { [HTTP::host] } {
          "test1*" -
          "www.test1*" {
            HTTP::redirect "http://www.test1.com/TrafficUI/mscui/page.aspx?cid=1&ptid=5"
          }
          "test2*" -
          "www.test2*" {
            HTTP::redirect "http://www.test2.com/TrafficUI/mscui/page.aspx?cid=1&ptid=10"
          }
          "test*" {
            HTTP::redirect "http://www.google.com/"
          }
        }
      }
    }
  • thanks for the help

     

     

    This is the error:

     

     

    Line: 4

     

    Char: 1

     

    Error: Syntax Error

     

    Code: 0

     

     

    also, i used your example and it never seems to get to the redirect if i use the domain with no URI

     

     

    also, is there a way to have an irule look for the host, then see what the uri is and act upon it

     

     

    thanks again
  • you think this is better than the if, elseif?

     

     

    when HTTP_REQUEST {

     

    if {[string tolower [HTTP::uri]] starts_with "/trafficui" } {

     

    pool PoolOne

     

    else {

     

    switch -glob "[HTTP::host][HTTP::uri]" {

     

    "*test1.com/" {

     

    HTTP::redirect "http://www.test1.com/trafficui/mscui/page.aspx?cid=1&ptid=10"

     

    }

     

    "*test2.com/" {

     

    HTTP::redirect "http://www.test2.com/trafficui/mscui/page.aspx?cid=1&ptid=10"

     

    }

     

    default {

     

    HTTP::redirect "http://test3.com/TrafficUI/mscui/page.aspx?cid=1&ptid=4&utcoffset=5"

     

    }

     

    }

     

    }

     

    }

     

     

    what i'd like to do with this one is *.test1.com/ (starts with anything other then traffcui) HTTP::redirect blahblah

     

     

    is it possible?
  • is there a better way to get this done? i tried a switch - glob [HTTP::uri] and then switch - glob [HTTP:host] but it just skipped right over the uri section

     

     

    this is working but does not look very scalable

     

     

    when HTTP_REQUEST {

     

    if {[string tolower [HTTP::uri]] starts_with "/trafficui" } {

     

    pool trafficui

     

    } elseif {[string tolower [HTTP::uri]] starts_with "/testuri" } {

     

    HTTP::redirect "http://www.testuri.com/TrafficUI/mscui/Page.aspx?pgid=598"

     

    } else {

     

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

     

    "test1.com" -

     

    "*.test1.com" {

     

    HTTP::redirect "http://wwv.test1.com/trafficui/mscui/page.aspx?cid=1&ptid=10"

     

    }

     

    "test2.com" -

     

    "*.test2.com" {

     

    HTTP::redirect "http://www.test2.com/TrafficUI/mscui/page.aspx?cid=1&ptid=5"

     

    }

     

    default {

     

    HTTP::redirect "http://www.test3.com/TrafficUI/mscui/page.aspx?cid=1&ptid=4&utcoffset=5"

     

    }

     

    }

     

    }

     

    }

     

     

    much appreciated