Forum Discussion
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
- Hannes_Rapp
Nimbostratus
Try something as follows. If you want to use 302 as a redirect method, make sure you also use the
close command afterTCP::closeevent disablewhen 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
Nimbostratus
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
Nimbostratus
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]
- Hannes_Rapp_162
Nacreous
Try something as follows. If you want to use 302 as a redirect method, make sure you also use the
close command afterTCP::closeevent disablewhen 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
Nimbostratus
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
Nacreous
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]
- Jay_Prasanth_13
Nimbostratus
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..
- Jay_Prasanth_13
Nimbostratus
I didn't get what for 5 , 6 and 7 in the script , what if I put some other value?
- Hannes_Rapp
Nimbostratus
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
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com