Forum Discussion
Capture part of URL to redirect to another
- Nov 17, 2022
Hello there,
if the requested information is always stored in variable KT1112_0_0_0= at request time, this script will capture exact variable value (not bound to length) and insert it in redirect url as acctNum valuewhen HTTP_REQUEST { if { [HTTP::uri] contains "LOAN" }{ set acctNum [findstr [HTTP::query] "KT1112_0_0_0=" 13 &] HTTP::redirect "https://website2.domain.com/path/app.aspx?acctNum=$acctNum&acctType=LOAN&type=Documents" } }
It's working in my lab
Hello there,
if the requested information is always stored in variable KT1112_0_0_0= at request time, this script will capture exact variable value (not bound to length) and insert it in redirect url as acctNum value
when HTTP_REQUEST {
if { [HTTP::uri] contains "LOAN" }{
set acctNum [findstr [HTTP::query] "KT1112_0_0_0=" 13 &]
HTTP::redirect "https://website2.domain.com/path/app.aspx?acctNum=$acctNum&acctType=LOAN&type=Documents"
}
}
It's working in my lab
This worked, but I had to make an adjustment to the findstr as it wasn't working. Here is the final iRule
when HTTP_REQUEST {
if { [HTTP::uri] contains "LOAN" }{
set acctNum [findstr [HTTP::query] "=" 1 &]
HTTP::redirect "https://website2.domain.com/path/app.aspx?acctNum=$acctNum&acctType=LOAN&type=Documents"
}
}
Thanks for the help!!
- CA_ValliNov 23, 2022MVP
I was capturing the full query parameter and skipping the first 13 characters (param name + "=" character) in order just to keep the value.
Be careful with you syntax, because if another parameter is passed in querystring before acctNum value (like that LOAN that triggers the if condition) it might be captured instead. If param name is dynamic (eg. numbers change), you could also capture a "static" part and skip the dynamic pattern using an appropirate syntax.
[findstr [HTTP::query] "KT1112" 13 &] will match all of the following param names, and save the param value after the "=" and up to first "&" character:
KT1112_0_0_0=
KT1112_1_2_3=
KT1112aaaaaa=
I really think you should configure the match to be as close as possible.
Regards
CA
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