Forum Discussion

kouriada_284551's avatar
kouriada_284551
Icon for Nimbostratus rankNimbostratus
Oct 09, 2017

this value is dynamically changed (like Apple = vendor1;Lemon = vendor2)

Hello guys, I have one problem for which I don't have enough irule's experiences, maybe someone will know...

 

I need to write irule which takes a value from one url and paste it to another, this value is dynamically changed (like Apple = vendor1;Lemon = vendor2), for example:

 

https://Hello.world.com/test/sun/A/Apple to redirect to

 

https://Hello.world.com/test/sun/B/Apple to redirect to

 

https://Hello.world.com/test/sun/A/Lemon to redirect to

 

https://Hello.world.com/test/sun/B/Lemon to redirect to

 

I have been thinking about something like this (just idea):

 

  1. when HTTP_REQUEST {
  2. if { [HTTP::uri] starts_with "/A/*" } {
  3. set VALUE [substr [HTTP::uri] "$*" ""]
  4. HTTP::redirect "$*:Olala/blabla"

} }

 

But I have no idea, how to take * (Apple, Lemon, ... basically whatever is hidden behind *) and insert it into new url, because * will be working like identifier of a particular vendor.

 

Or is possible to solve this problem via Policy?

 

Thank you for your hints AK

 

1 Reply

  • You can try something like that:

    when HTTP_REQUEST {
        if {[scan [HTTP::uri] "/test/sun/%s/%s" val1 val2] == 2} {
            switch $val1 {
                "A" {HTTP::redirect "http://Bad.day.corp/Message?channel1=${val2}:Olala/blabla"}
                "B" {HTTP::redirect "http://Bad.day.corp/Message?channel2=${val2}:Olala/blabla"}
            }
        }
    }