redirect to v9.x rule

I have a v4.x rule I’m trying to migrate to v.9x

v4.x Rule looks like this:

if (client_addr == one of OPS_IP) {

use pool FS_OPS_Pool

}

else if (client_addr == one of Admin_IP) {

use pool FS8

}

else {

redirect to “http://my_url.com/accessdenied.htm”

}

v9.x Rule looks like this:

when CLIENT_ACCEPTED {

if { [matchclass [IP::remote_addr] equals $::OPS_IP] } {

pool FS-OPS

}

elseif { [IP::addr [IP::client_addr] equals $::Admin_IP] } {

pool FS-Prod

}

else discard

}

My question is what trick can I use to send a browser to another URL??

You can use HTTP::redirect to send a redirect back to the client to a new URL

Click here

Aaron

when CLIENT_ACCEPTED {
  if { [matchclass [IP::remote_addr] equals $::OPS_IP] } {
    pool FS-OPS
  } elseif { [IP::addr [IP::client_addr] equals $::Admin_IP] } {
      pool FS-Prod
  } else { 
      HTTP::redirect "http://my_url.com/accessdenied.htm"
  }
}

Looks like Hoolio beat me to it!

You’re first rule had two conditions for getting traffic to a specific pool, whereas your new rule dumps every class-defined request into FS-Prod, so they are not identical functionally..

In any event, you can use the timing on command to know for sure which is more efficient. Check out the wiki for usage.

I’m getting this error

line 7: [command is not valid in current event context (CLIENT_ACCEPTED)] [HTTP::redirect “http://my_url.com/accessdenied.htm”]

Is the redirect command valid with CLIENT_ACCEPT or can I only use it with HTTP_REQUEST?

Yes, the HTTP::redirect command is only valid within a HTTP event.

Another thing: In your iRule, if $::OPS_IP and $::Admin_IP are data groups, then you’ll have to use the matchclass command and not a straight equality. If you just use an equals comparison, then I believe it will only compare against the first item in the data group.

-Joe

Man, fit me for the dunce cap today!

I have changed the rule a bit but it appears not to fire what am I missing?

when CLIENT_ACCEPTED {

if { [matchclass [IP::remote_addr] equals $::OPS_IP] } {

pool FS-OPS

} elseif { [matchclass [IP::remote_addr] equals $::ADMIN_IP] } {

pool FS-Prod

}

}

when HTTP_REQUEST {

HTTP::redirect “http://myurl/accessdenied.htm”

}

I think it would be simpler to put the whole rule in the HTTP_REQUEST event if you want to send an HTTP redirect. Also, the redirect should be in the else of the if/elseif/else chain so that clients that aren’t in either class will be redirected.

See if this works better for you:

when HTTP_REQUEST {
   if { [matchclass [IP::remote_addr] equals $::OPS_IP] } {
      pool FS-OPS
   } elseif { [matchclass [IP::remote_addr] equals $::ADMIN_IP] } {
      pool FS-Prod
   } else {
      HTTP::redirect "http://myurl/accessdenied.htm"
   }
}

Aaron