Forum Discussion

Peak_10_71174's avatar
Peak_10_71174
Icon for Nimbostratus rankNimbostratus
Oct 12, 2009

irule redirect logic and syntax

I'm not a developer and I wanted to verify that the following irule change would work as I intend it to before I put it in a production environment:

 

I currently have an irule setup to redirect certain incoming http requests on a virtual server to various pools other than the default pool configured on the virtual server. Here is the irule that we have in place in our production environment:

 

when HTTP_REQUEST {

 

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

 

"*redirect1" -

 

"*redirect2/" -

 

"/redirect3/*" -

 

"*/redirect4/*" {

 

pool other_pool_1

 

log local0. "other_pool_1 chosen."

 

}

 

"/redirect4" -

 

"/redirect4/*" {

 

pool other_pool

 

log local0. "other_pool_2 chosen."

 

}

 

default {

 

pool default_pool

 

log local0. "default_pool chosen."

 

}

 

}

 

}

 

I need to edit the above irule so that any incoming request that matches "/redirect3/*.htm*" is redirected to the default pool, but anything that matches the less specific match of "/redirect3/*" is redirected to other_pool_1. Below is the irule that I have edited to hopefully make this work. I was hoping someone could review it and see if they have any concerns/questions:

 

when HTTP_REQUEST {

 

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

 

"/redirect3/*.htm*" {

 

pool default_pool

 

log local0. "HTML hit - default_pool chosen"

 

}

 

"*redirect1" -

 

"*redirect2/" -

 

"/redirect3/*" -

 

"*/redirect4/*" {

 

pool other_pool_1

 

log local0. "other_pool_1 chosen."

 

}

 

"/redirect4" -

 

"/redirect4/*" {

 

pool other_pool

 

log local0. "other_pool_2 chosen."

 

}

 

default {

 

pool default_pool

 

log local0. "default_pool chosen."

 

}

 

}

 

}

1 Reply

  • That looks good. One thing I noticed is that */redirect4/* is listed before /redirect4/*. I don't think the latter will ever get matched as */redirect4/* will match /redirect4/anything in addition to anything/redirect4/anything:

     

     

    % string match */redirect4/* /redirect4/anything

     

    1

     

    % string match */redirect4/* anything/redirect4/anything

     

    1

     

     

    Aaron