For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Jay_Prasanth_13's avatar
Jay_Prasanth_13
Icon for Nimbostratus rankNimbostratus
Oct 14, 2014

How to create iRule to forward request depending on context input

For eg. when user type http://abc.com/aa/bb/cc/xx/yy/zz , iRule should redirect to http://abc.com/aa/bb/cc?t1=xx&t2=yy&t3=zz

 

Explanation of above Example

 

http://abc.com/aa/bb/cc/xx/yy/zz [ aa,bb,cc are static values and xx,yy,zz are dynamic values (user provided inputs ) ] http://abc.com/aa/bb/cc?t1=xx&t2=yy&t3=zz [ &,t1,=,xx,t2,t3, are static)

 

Expected result: User inputs xx,yy,zz should sit in the appropriate output context path ie. xx should sit after t1= , yy after t2= , zz after t3=

 

9 Replies

  • Try something as follows. If you want to use 302 as a redirect method, make sure you also use the

    TCP::close
    close command after
    event disable

        when HTTP_REQUEST {
    
        if { [HTTP::uri] starts_with "/aa/bb/cc" } {
          set PREFIX_STATIC "/aa/bb/cc"
          log local0. "Original URI: [HTTP::uri]"
          set XX_VAL [ getfield [HTTP::uri] "/" 5]
          set YY_VAL [ getfield [HTTP::uri] "/" 6]
          set ZZ_VAL [ getfield [HTTP::uri] "/" 7]
          log local0. "XX_VAL = $XX_VAL | YY_VAL = $YY_VAL | ZZ_VAL = $ZZ_VAL"
          log local0. "Redirect destination: [HTTP::host]$PREFIX_STATIC?t1=$XX_VAL&t2=$YY_VAL&t3=$ZZ_VAL"
          HTTP::respond 301 Location "[HTTP::host]$PREFIX_STATIC?t1=$XX_VAL&t2=$YY_VAL&t3=$ZZ_VAL"
          event disable
        }
    }
    

    Oct 14 10:12:08 local/tmm info tmm[15625]: Rule irule_asd-test : Original URI: /aa/bb/cc/f3/f4/f5

    Oct 14 10:12:08 local/tmm info tmm[15625]: Rule irule_asd-test : XX_VAL = f3 | YY_VAL = f4 | ZZ_VAL = f5

    Oct 14 10:12:08 local/tmm info tmm[15625]: Rule irule_asd-test : Redirect destination: www.abc.com/aa/bb/cc/?t1=f3&t2=f4&t3=f5
    • Jay_Prasanth_13's avatar
      Jay_Prasanth_13
      Icon for Nimbostratus rankNimbostratus
      Working fine for "/" (slash) separation in URI . What if the separation is "-"(dash) ? For eg: if the url is http://abc.com/aa/bb/cc/xx-yy-zz iRule should redirect to http://abc.com/aa/bb/cc?t1=xx&t2=yy&t3=zz
    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      Keep everything the same, except the 3 lines below. (Untested solution) set XX_VAL [ getfield [HTTP::uri] "-" 0] set YY_VAL [ getfield [HTTP::uri] "-" 1] set ZZ_VAL [ getfield [HTTP::uri] "-" 2]
  • Try something as follows. If you want to use 302 as a redirect method, make sure you also use the

    TCP::close
    close command after
    event disable

        when HTTP_REQUEST {
    
        if { [HTTP::uri] starts_with "/aa/bb/cc" } {
          set PREFIX_STATIC "/aa/bb/cc"
          log local0. "Original URI: [HTTP::uri]"
          set XX_VAL [ getfield [HTTP::uri] "/" 5]
          set YY_VAL [ getfield [HTTP::uri] "/" 6]
          set ZZ_VAL [ getfield [HTTP::uri] "/" 7]
          log local0. "XX_VAL = $XX_VAL | YY_VAL = $YY_VAL | ZZ_VAL = $ZZ_VAL"
          log local0. "Redirect destination: [HTTP::host]$PREFIX_STATIC?t1=$XX_VAL&t2=$YY_VAL&t3=$ZZ_VAL"
          HTTP::respond 301 Location "[HTTP::host]$PREFIX_STATIC?t1=$XX_VAL&t2=$YY_VAL&t3=$ZZ_VAL"
          event disable
        }
    }
    

    Oct 14 10:12:08 local/tmm info tmm[15625]: Rule irule_asd-test : Original URI: /aa/bb/cc/f3/f4/f5

    Oct 14 10:12:08 local/tmm info tmm[15625]: Rule irule_asd-test : XX_VAL = f3 | YY_VAL = f4 | ZZ_VAL = f5

    Oct 14 10:12:08 local/tmm info tmm[15625]: Rule irule_asd-test : Redirect destination: www.abc.com/aa/bb/cc/?t1=f3&t2=f4&t3=f5
    • Jay_Prasanth_13's avatar
      Jay_Prasanth_13
      Icon for Nimbostratus rankNimbostratus
      Working fine for "/" (slash) separation in URI . What if the separation is "-"(dash) ? For eg: if the url is http://abc.com/aa/bb/cc/xx-yy-zz iRule should redirect to http://abc.com/aa/bb/cc?t1=xx&t2=yy&t3=zz
    • Hannes_Rapp_162's avatar
      Hannes_Rapp_162
      Icon for Nacreous rankNacreous
      Keep everything the same, except the 3 lines below. (Untested solution) set XX_VAL [ getfield [HTTP::uri] "-" 0] set YY_VAL [ getfield [HTTP::uri] "-" 1] set ZZ_VAL [ getfield [HTTP::uri] "-" 2]
  • Thanks Hannes, working perfect .

     

    We are facing some caching issue , but I think it is related to app side , need to fine tune.

     

    Thanks again..

     

    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      You can use any values of any lengths you want. (e.g www.abc.com/aa/bb/cc/hhhhhhhhhhh/ssssssss/llllllllllll would work exactly the same) For example: set XX_VAL [ getfield [HTTP::uri] "/" 5] - returns anything entered in between fourth and fifth slash symbol as a string