Forum Discussion
mguned_60772
Feb 19, 2010Nimbostratus
URL Rewrite findstr
Trying to do the following:
Redirect -
https://oldsite.com/xxx/xxx/xxx.asp?firststring=FIRSTxxxx_xxxxsecondstring=SECOND
to -
http://newsite.com/xxx.aspx?xxxxxx=FIRSTxxxxx=SECOND
Here is what I have tried to no avail:
elseif { [HTTP::uri] contains "/xxx/xxx/xxx.asp" } { set FIRST [findstr [HTTP::uri] "xxx" 4 ";"] set SECOND [findstr [HTTP::uri] "xxx" 6 ";"] HTTP::redirect "http://newsite.com/xxx.aspx?xxx=$FIRSTxxx=$SECOND"}
Any help is much appreciated!
Cheers!
- hooleylistCirrostratusNormally I'd suggest using URI::query to parse the parameter values and then insert them in the redirect. However, there is a bug in the URI::query command (described in this post Click here).
elseif { [HTTP::path] eq "/xxx/xxx/xxx.asp" } { Parse the value of param_one from the URI if {$query starts_with "param_one="}{ set FIRST [findstr $query "param_one=" 10 &] log local0. "\$FIRST: $FIRST" } else { Parameter wasn't at the start of the query string, so check for ¶m_one= in the query string Need to hardcode the length of the parameter name + 2 for findstr set FIRST [findstr $query "¶m_one=" 11 &] log local0. "\$FIRST: $FIRST" } Parse the value of param_2 from the URI if {$query starts_with "param_2="}{ set SECOND [findstr $query "param_2=" 8 &] log local0. "\$SECOND: $SECOND" } else { Parameter wasn't at the start of the query string, so check for ¶m_2= in the query string Need to hardcode the length of the parameter name + 2 for findstr set SECOND [findstr $query "¶m_2=" 9 &] log local0. "\$SECOND: $SECOND" } HTTP::redirect "http://newsite.com/xxx.aspx?xxx=$FIRSTxxx=$SECOND"}
- mguned_60772NimbostratusThanks for the info...working on this now. BTW, if you could do a URI::query ...what would it look like?
- mguned_60772NimbostratusIs it possible to grab just 4 characters after FIRST?
- hooleylistCirrostratusYou can use [string range $string 0 3] to get a substring from $string. If you want help, can you post a more exact anonymized example of the URI you're trying to parse?
- mguned_60772NimbostratusI am still having trouble extracting the 4 characters associated with mailDrop ... it seems to grab everything behind mailDrop= and not just the 4 characters.
- hooleylistCirrostratusSorry.. typing faster than I was reading. The URI::query command should return whatever is between mailDrop= and the next & or the end of the string, regardless of the length of that value. Are you wanting to only use the first four characters of the mailDrop parameter value even if it's longer in some cases? Do you see a & in the redirect string (or what exactly do you see in the string and is that what the mailDrop parameter value is set to in the original URI)?
- mguned_60772NimbostratusSo here is what I have:
- hooleylistCirrostratusCan you try this then:
- mguned_60772NimbostratusSorry, I missed that on your earlier response and yes it works! Thanks again for the help...much appreciated.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects