Forum Discussion

Raj_74912's avatar
Raj_74912
Icon for Nimbostratus rankNimbostratus
Jun 02, 2010

Greedy iRule. Need not so greedy one.

Guys and Gals,

 

 

I currently have a problem that I am trying to solve. I have a website called www.abc.com and want all requests only going to www.abc.com// to go to a different pool than normal traffic.

 

 

Following is what I wrote but the problem is traffic going to www.abc.com//1234/page1.html or www.abc.com//page1.html all goes to redirect pool. I need only

 

www.abc.com") and ([HTTP::uri] matches_regex "^\/.*?\/")) and ( not ([HTTP::cookie exists $::cknameexist]))} {

 

set ::proxypool 1

 

pool proxy.abc.com-80

 

}

 

}

 

when HTTP_RESPONSE {

 

if {$::proxypool == 1} {

 

HTTP::cookie insert name "Proxy" value "Enabled" domain "abc.com" path "/"

 

}

 

if {($::proxypool == 0)} {

 

HTTP::cookie remove $::ckname

 

}

 

}

 

 

 

Thanks in advance for all your expert help.

 

 

Raj

 

4 Replies

  • Hi Raj,

     

     

    First, I'd suggest changing all of your variables to local ones and removing the RULE_INIT event. Any variable set in RULE_INIT defaults to be a global. Global variables will be shared across all connections for all virtual servers. Then I'd replace the matches_regex command with a string function. Are you trying to literally matching only a URI of //? If so you can check for it using [HTTP::uri] eq "//". If that's not what you're after, can you clarify?

     

     

    Thanks, Aaron

     

     

  • I can change the variables to local. I am trying to only match URI that starts and end with with /
  • oh wow. I just noticed the form edited my text folks.

     

     

    So to clarify I am only trying to match on URI that start and end with /something_here/. What is happening currently is that the iRule is also matching on things like /something_here/1234/page1.html or like /something_here/page1.html.
  • You could do this with two string functions instead of a regex for better effciency:

     

     

    [HTTP::uri] starts_with "/" && [HTTP::uri] ends_with "/"

     

     

    For information only, you could use a regex like this to match / or /anything/:

     

     

    ^(?:/.*/|/)$

     

     

    tests:

     

     

    % regexp {^(?:/.*/|/)$} /test/123/

     

    1

     

    % regexp {^(?:/.*/|/)$} /

     

    1

     

    % regexp {^(?:/.*/|/)$} /test/123

     

    0

     

    %

     

     

    Aaron