Help with IRule

Can you please help with the following iRule which is not working at all.

For client IPs that do NOT match SS_CMS_Nets and hit the URI specified in SS_CMS_URLs redirect back to /

when HTTP_REQUEST {

if { not ([matchclass [IP::client_addr] equals $::SS_CMS_Nets]) and ([string tolower [HTTP::uri]] contains $::SS_CMS_URLs) } {

HTTP::redirect “/”

}

}

SS_CMS_Nets

192.168.1.0/255.255.255.0

SS_CMS_URLs

“/server2”

Many thanks,

esexon

What version are you running? Is there any error in the \var\log\ltm? The iRule looks valid on version 9.x it will cause the VIP to bind to TMM0 is on a newer platform. If you are running 10 or above you need o rewrite the iRule using the class command.

Thanks,

I am running BIG-IP 10.2.1 Build 297.0 Final.

Hi sorry,

There are no errors in the ltm logs. What would I need to add to the iRule rewrite to get this to work?

Many thanks,

Evan

I have always assumed the redirect needed an absolute path, so:

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

Many thanks for the reply. I have tried the absolute URL but this does not make any difference.

Oops, I see it now, try this line instead:

when HTTP_REQUEST {
    if { not ([matchclass [IP::client_addr] equals $::SS_CMS_Nets]) and ([matchclass [string tolower [HTTP::uri]] contains $::SS_CMS_URLs]) } {
        HTTP::redirect "/"
    }
}

Thanks very much. This has worked perfectly.

To be 10.x friendly and not demote your Virtual from CMP use this instead.

when HTTP_REQUEST {

if {not {[class match [IP::client_addr] equals SS_CMS_Nets]) and ([class [string tolower [HTTP::uri]] contains SS_CMS_URLs]) } {

HTTP::redirect “/”

}

}

OK… can’t edit my post and put the code formatting around it, so sorry for the repost.

when HTTP_REQUEST {
if {not {[class match [IP::client_addr] equals SS_CMS_Nets]) and ([class [string tolower [HTTP::uri]] contains SS_CMS_URLs]) } {
HTTP::redirect "/"
}
}

Fixed a couple of minor typos:

when HTTP_REQUEST {
    if {not ([class match [IP::client_addr] equals SS_CMS_Nets]) and ([class match [string tolower [HTTP::uri]] contains SS_CMS_URLs]) } {
        HTTP::redirect "/"
    }
}

Aaron

Guys, thanks very much. I have only got around to testing this today. The rule seems to ignore all IP addresses listed in SS_CMS_Nets and redirects every client to “/”

Not sure how to fix this, any ideas?