Forum Discussion

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

How to create iRule to forward request depending on context input which has hyphen sign "-" in the url

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

 

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=

 

3 Replies

  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    Try this

    set newuri {/aa/bb/cc/}
    set str [split [lindex [split [HTTP::uri] /] end] -]
    set parm "t1=[lindex $str 0],t2=[lindex $str 1],t2=[lindex $str 2]"
    HTTP::uri "$newuri?$parm"
    
  • Thank you , I got the clue. Below rule worked for me. But minor issue popping up now.

     

    if { [HTTP::uri] starts_with "/aa/bb/cc/" } { set PREFIX_STATIC "/cs/ccs-cctc/jobs" set XX_VAL [ getfield [HTTP::uri] "-" 2] set YY_VAL [ getfield [HTTP::uri] "-" 3] set ZZ_VAL [ getfield [HTTP::uri] "-" 4] set XX_NEW [split [lindex [split $XX_VAL /] end] -] HTTP::uri "$PREFIX_STATIC?q1=$XX_NEW&q2=$YY_VAL&q3=$ZZ_VAL" }

     

    This iRule only picking the 4 the field value "zz" not adding subsequent values to URI.

     

    For eg. If user hit http://abc.com/aa/bb/cc/xx-yy-zz-blah-blah , endresult should be http://abc.com/aa/bb/cc?q1=xx&q2=yy&q3=zz-blah-blah

     

    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      e.g. configuration root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 source-address-translation { type automap } vs-index 3 } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo ltm pool foo { members { 200.200.200.101:80 { address 200.200.200.101 } } } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [HTTP::uri] starts_with "/aa/bb/cc/" } { if { [scan [HTTP::uri] {/aa/bb/cc/%[^-]-%[^-]-%s} a b c] == 3 } { set PREFIX_STATIC "/cs/ccs-cctc/jobs" HTTP::uri "${PREFIX_STATIC}?q1=${a}&q2=${b}&q3=${c}" } } } } trace [root@ve11a:Active:In Sync] config ssldump -Aed -nni 0.0 port 80 New TCP connection 1: 172.28.24.1(38566) <-> 172.28.24.10(80) 1415107890.5317 (0.0013) C>S --------------------------------------------------------------- GET /aa/bb/cc/xx-yy-zz-blah-blah HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Host: 172.28.24.10 Accept: */* --------------------------------------------------------------- New TCP connection 2: 200.200.200.14(38566) <-> 200.200.200.101(80) 1415107890.5377 (0.0045) C>S --------------------------------------------------------------- GET /cs/ccs-cctc/jobs?q1=xx&q2=yy&q3=zz-blah-blah HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Host: 172.28.24.10 Accept: */* ---------------------------------------------------------------