Percent character encoding and irules

I have an irule that looks at the request_uri to determine which pool to use:

if (http_uri matches_regex “/[Vv][Ee][Nn][Dd][Oo][Rr]_[Mm][Gg][Tt]”) {

use pool lm-pmweb-2k3

}

else {

use pool lm-web-prod

}

The problem is that the 2k3 IIS devices are building a redirect to add the trailing / onto the directory name, but encoding the _ character.

If I request http://site.d.com/vendor\_mgt, IIS responds with a 302, and sends me to http://site.d.com/vendor_mgt/ . The problem is that by replacing the _ with a %5F, the irule doesn’t match any longer, and I go to the wrong pool.

Is there a way to make the irule decode the %5F so that it will match?

I’d suggest making a change like:

if (http_uri matches_regex "/[Vv][Ee][Nn][Dd][Oo][Rr].*[Mm][Gg][Tt]") {
use pool lm-pmweb-2k3
}
else {
use pool lm-web-prod
}

This would match vendor and mgt, regardless of what seperated them.

You could, of course, make a more strict version to only match a certain number of characters if you so chose.

-Colin

Mark,

if you are running BIG-IP 4.6.x or newer, you can use following rule:

rule match_vendor_mgt {
  if(tolower(decode_uri(http_uri)) == "/vendor_mgt")
      use pool lm-pmweb-2k3
  } else {
      use pool lm-web-prod
  }
}

The decode_uri function translates %XX escape following rules defined in RFC2396. The tolower function translates ASCII uppercase characters to their lowercase equivalents. The above rule should be more efficient than regex matching.

BIG-IP versions older than 4.6 do not support the tolower function.