Forum Discussion

AlexDeMarco's avatar
AlexDeMarco
Icon for Nimbostratus rankNimbostratus
Oct 07, 2013

How to append to a match_class

I have this code:

 

if { ([class match $req_uri starts_with PROD_uri_to_redirecttossl]) } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" }

 

but want something like this:

 

if { ([class match $req_uri starts_with PROD_uri_to_redirecttossl]) or ([class match $req_uri starts_with PROD_uri_to_redirecttossl]+"/*") } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" }

 

Is that possible in an Irule, so I have datagroup: /about /help

 

I want the if to keep off of /about or /about/* but do not want to add /about/* to the dategroup.

 

Any suggestions?

 

thanks!

 

7 Replies

  • okay well that did not work I get a connection reset in the browser..

     

    So the question remains can I append to data returned via a class match?

     

    if { ([class match $req_uri starts_with PROD_uri_to_redirecttossl] or [class match $req_uri starts_with PROD_uri_to_redirecttossl]+"/*") } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" }

     

    This does not work,.. any ideas?

     

  • You can sort of think of a class like a list or array, in which trying to add a string to the end of the search criteria isn't going to add a value to each list element but rather to the reference to the list itself. Like searching a list, you'd necessarily have to iterate through each of its elements and add the string value before evaluation. Fortunately I don't thing you need to do that. You've specified that you want to send a redirect if the URI starts with "/about", which would encompass "/about", "/about/*", and "/about/anything-else-after-this-lowest-common-denominator-uri". In other words, the second URI evaluation would be unnecessary.

     

  • Kevin, thanks.. wouldn't it also hit on /aboutme or /aboutyou which is not what I want.

     

    I need to redirect /about or /about/*

     

    not exactly sure how to do this although it seems simple enough.

     

  • Okay, this may seem a little odd, but I've gotten to work as follows:

    Data group:

    /about/
    /help/
    

    iRule:

    when HTTP_REQUEST { 
        if { [string first "/" [HTTP::uri] 1] eq -1 } {
             URI doesn't have a second "/" so just return URI
            set mod_uri [HTTP::uri]
        } else {
             return the first level URI minus trailing "/"
            set mod_uri [string range [HTTP::uri] 0 [string first "/" [HTTP::uri] 1]]
        }
        if { ( [class match "${mod_uri}/" equals my-dg] ) or ( [class match $mod_uri starts_with my-dg] ) } {
             do something here
            log local0. "match"
        }
    }
    

    Essentially, I take the requested URI (ex. "/about/me"), strip it down to its first level path minus the trailing slash ("/about"), then compare it two times against the data group:

    • Does the data group entry "/about/" equal the modified URI + trailing slash?
    • Does the data group entry "/about/" start with the modified URI?

    It will match "/about", "/about/", and "/about/me", but not "/aboutme".

  • ahh ok I follow you, so the dategroup would just have /about/ right?