Forum Discussion

Cindy_127211's avatar
Cindy_127211
Icon for Nimbostratus rankNimbostratus
Apr 09, 2006

Rule that redirects based on length of [HTTP::uri]

I have a rule in 4.5 that does the following, but cannot get the same rule to work in version 9.1.1. Can you tell me what I'm doing wrong for the 9.1.1 version?

 

 

Thanks!

 

 

Version 4.5.13

 

 

rule siebel_redirect_test {

 

if (http_uri > 1) {

 

use pool siebelqa

 

}

 

else {

 

redirect to "http://siebel-qa.americancentury.com/fins_enu/"

 

}

 

}

 

 

 

Version 9.1.1

 

 

rule siebel_redirect_test {

 

when HTTP_REQUEST {

 

if { [HTTP::uri] > 1 } {

 

use pool siebelqa

 

}

 

else {

 

HTTP::redirect "http://[HTTP::host]fins_enu/"

 

}

 

}

 

}

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    I think this should work for you:

     

     

    rule siebel_redirect_test {

     

    when HTTP_REQUEST {

     

    if { [string length [HTTP::uri]] > 1 } {

     

    pool siebelqa

     

    }

     

    else {

     

    HTTP::redirect "http://[HTTP::host]/fins_enu/"

     

    }

     

    }

     

    }

     

     

    I think you need to use 'string length' to do the comparison. In 9.x, the 'use' in 'use pool my_pool' has been deprecated in favor of 'pool my_pool'.

     

     

    I also added a forward slash after [HTTP::host] as there isn't one by default.

     

     

    Aaron
  • Honestly, I'm not sure how your rule was working on 4.x becuase the http_uri value is a string and you are comparing it to a number. What you want is the string length. This should work for you using the builtin "string" TCL command.

    when HTTP_REQUEST {
      if { [string length [HTTP::uri]] > 1 } {
        use pool siebelqa
      } else {
        HTTP::redirect "http://[HTTP::host]/fins_enu/"
      }
    }

    Note, I added an extra slash in your redirect after the HTTP::host value. I was assuming you are redirecting to the same host with the /fins_enu/ path. If you are trying to append "fins_enu/" to the host value then leave it as is.

    BTW, you could make the rule much simpler if you set the default pool on your virtual server to "siebelqa". Then your rule could look like this

    when HTTP_REQUEST {
      if { [string length [HTTP::uri]] == 1 } {
        HTTP::redirect "http://[HTTP::host]/fins_enu/"
      }
    }

    -Joe