URL based redirect...

Hello…

I have 3 instances where I need certain URL’s to be directed to a specific pool (the same pool), http://websitename/calendar, http://websitename/cgi-bin and http://websitename/smd/student/2008. Currently I have 3 separate iRules applied to the VS for each of these situations, all that look like the following, with the appropriate name following the /:

when HTTP_REQUEST {

if { [HTTP::uri] starts_with “/smd/student/2008” } {

pool URMCPublicExclusion_HTTP_Pool

} else {

pool URMCPublic_http_Pool

}

}

Can I combine all 3 of these into one iRule? I am having issues with one of these iRules working prperly (one that I know of), and I was curious if it was related to having 3 sperate rules. Any help would be appreciated. Thanks!

Chris

I think I see why this is not working with 3 separate rules, so I took a crack at combining the 3…I know this is not the most efficient way, but hopefully I am on the right track. I am not a programmer and new to iRules, so please be gentle!

when HTTP_REQUEST {

if { string tolower [HTTP::uri] starts_with “/calendar” } {

pool URMCPublicExclusion_HTTP_Pool

} elseif { string tolower [HTTP::uri] starts_with “/smd/student/2008” } {

pool URMCPublicExclusion_HTTP_Pool

} elseif { string tolower [HTTP::uri] starts_with “/cgi-bin” } {

pool URMCPublicExclusion_HTTP_Pool

}

else {

pool URMCPublic_http_Pool

}

}

Thanks

Chris

I made one more change to the irule…learning as I go!

when HTTP_REQUEST {

if {[string tolower [HTTP::uri]] starts_with “/calendar” } {

pool URMCPublicExclusion_HTTP_Pool

} elseif {[string tolower [HTTP::uri]] starts_with “/smd/student/2008” } {

pool URMCPublicExclusion_HTTP_Pool

} elseif {[string tolower [HTTP::uri]] starts_with “/cgi-bin” } {

pool URMCPublicExclusion_HTTP_Pool

}

}

If the request does not meet any of these criteria, it will pass along to the default pool, correct? Thanks!

That should work for you, but you are doing a separate string allocation in each of the if/elseif’s. If I were you, I’d go with the switch route (just my own preference. And since, you are using the same case for each of the conditions, a switch is extra-easy to read. Either way should work for you though. You pick what is easier for you to maintain.

Here’s the switch version of your iRule:

when HTTP_REQUEST {
  switch -glob [string tolower [HTTP::uri]] {
    "/calendar*" -
    "/smd/student/2008*" -
    "/cgi-bin*" {
       pool URMCPublicExclusion_HTTP_Pool
    }
  }
}

The -glob argument is for file-type globbing (wildcards).

You can check out the syntax for the switch statement here:

Click here

And, yes, if none of the conditions are met, it will default to the default pool assigned to the virtual server.

-Joe

Thanks very much Joe!

I had read a post or two about using a switch but wasn’t sure how to structure it! This should work perfectly…Thanks again for your help!

Chris