Forum Discussion

Born_7758's avatar
Born_7758
Icon for Nimbostratus rankNimbostratus
Jul 18, 2011

Modify URI among other things

Hello Everyone,

 

 

Here's what I am trying to do:

 

 

 

I have a datagroup called payment_resp_1

 

 

 

When I receive a request I want to match it to the URIs in the datagroup, modify it, and then forward it to a specific member in a pool.

 

 

 

Here is the contents of the datagroup:

 

 

 

/paymentresponse1.jsf

 

/paymenterror1.jsf

 

/paymentsuccess1.jsf

 

 

 

So if the HTTP request comes in as http://192.168.1.2:434/paymentresponse1.jsf I would like to modify it to /CSU/paymentresponse.jsf and forward it to a specific member in the pool, say for example 10.48.52.58.

 

 

 

and if it came in as http://192.168.1.2:434/paymenterror1.jsf I would like to modify it to /CSU/paymenterror.jsf and forward it the same way.

 

 

 

Here is an iRule that I wrote to start off. Can someone please take a look at it and let me know if I am in the right track and if possible supply a better solution.

 

 

 

 

 

when HTTP_REQUEST {

 

 

 

 

 

if {[matchclass [HTTP::uri] equals $::payment_resp_1]} {

 

HTTP::uri "/CSU/paymentresponse.jsf"

 

pool payment_resp member 10.48.52.58 8080

 

}

 

}

 

 

 

 

 

 

Thanks in advance

 

 

 

  • I tried playing with this a bit to include three datagroups and 3 pool members. When I try to click Update I get this message:

     

     

    ine 11: [undefined procedure: elseif] [elseif {$line ne ""}{

     

    HTTP::uri $uri_2

     

    pool payment_resp member 10.48.52.66 8080

     

    } ]

     

     

     

    Here is the iRule

     

     

     

    when HTTP_REQUEST {

     

     

    set uri_1 [findclass [HTTP::path] $payment_resp_1A " "]

     

    set uri_2 [findclass [HTTP::path] $payment_resp_1B " "]

     

    set uri_3 [findclass [HTTP::path] $payment_resp_1C " "]

     

     

    if {$line ne ""}{

     

    HTTP::uri $uri_1

     

    pool payment_resp member 10.48.52.58 8080

     

    }

     

    elseif {$line ne ""}{

     

    HTTP::uri $uri_2

     

    pool payment_resp member 10.48.52.66 8080

     

    }

     

    elseif {$line ne ""}{

     

    HTTP::uri $uri_3

     

    pool payment_resp member 10.48.52.77 8080

     

    }

     

    }

     

  • If you have a different destination for each URI, you could use the original example I posted and a single datagroup:

    Datagroup line sample:

    /old_uri1 /new_uri1 ip1 port1

    /PaymentResponse1.jsf /CSU/PaymentResponse.jsf 10.48.52.58 8080

    And the iRule:

    
    when HTTP_REQUEST {
    
       set line [findclass [HTTP::path] $::uri_class]
       if {$line ne ""}{
          HTTP::uri [lindex $line 0]
          pool payment_resp member [lindex $line 1] [lindex $line 2]
       }
    }
    

    Aaron
  • Alright I got it to work!

     

     

    The only problem I'm having is that once it modifies the URI and takes me to that page, there are other web parts that arent showing. Like for example there are a couple of images that don't show up. I'm pretty sure this is because the images have a different URI and it's not included in the iRule.

     

     

    So my question is, how can I insert a line into the iRule that will let any other URI through without modifying it?