Forum Discussion
How to parse a guid from a uri to using in a redirection
I need to keep the guid of a uri and redirect to a new uri using the guid
Whats the best way to accomplish this.
original uri: en/server/GUID-876D26ED-3B49-41EB-8470-78D3F60F1360addHistory=true&filename=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357.xml&docid=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357&inner_id=&tid=&query=&scope=&resource=&eventType=lcContent.loadDocGUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357
Want to capture guid after docid= then redirect to
/en/server/guid
16 Replies
- VernonWells
Employee
when HTTP_REQEUST { set guid [findstr [HTTP::query] "docid=" 6 &] if { $guid ne "" } { HTTP::redirect "http://host.example.com/en/server/$guid" } }Naturally you should substitute an appropriate name for "host.example.com". This will not redirect if the docid query parameter is not found, and it makes no effort to validate the GUID.
- jmartinez_44554
Nimbostratus
Thanks for the reply. I'm getting this error when trying to save the rule. 01070151:3: Rule [/Common/livelibrarytest_redirects] error: /Common/livelibrarytest_redirects:1: error: [unknown event (HTTP_REQEUST)][when HTTP_REQEUST { set guid [findstr [HTTP::query] "docid=" 6 &] if { $guid ne "" } { HTTP::redirect "http://host.example.com/en/server/$guid" } }]
- Vernon_97235Historic F5 Account
when HTTP_REQEUST { set guid [findstr [HTTP::query] "docid=" 6 &] if { $guid ne "" } { HTTP::redirect "http://host.example.com/en/server/$guid" } }Naturally you should substitute an appropriate name for "host.example.com". This will not redirect if the docid query parameter is not found, and it makes no effort to validate the GUID.
- jmartinez_44554
Nimbostratus
Thanks for the reply. I'm getting this error when trying to save the rule. 01070151:3: Rule [/Common/livelibrarytest_redirects] error: /Common/livelibrarytest_redirects:1: error: [unknown event (HTTP_REQEUST)][when HTTP_REQEUST { set guid [findstr [HTTP::query] "docid=" 6 &] if { $guid ne "" } { HTTP::redirect "http://host.example.com/en/server/$guid" } }]
- VernonWells
Employee
Apologies. I spelled "REQUEST" incorrectly. It should be HTTP_REQUEST.
Also, you need to ensure that an http profile is applied to the same Virtual Server to which you will apply this iRule.
- jmartinez_44554
Nimbostratus
Wow I missed the misspelling too. Thanks. The rule fires but its bringing the rest of the original url after the guid along with it to the redirected page. Any way to insure its just the guid that gets brought over?
- Vernon_97235Historic F5 Account
Apologies. I spelled "REQUEST" incorrectly. It should be HTTP_REQUEST.
Also, you need to ensure that an http profile is applied to the same Virtual Server to which you will apply this iRule.
- jmartinez_44554
Nimbostratus
Wow I missed the misspelling too. Thanks. The rule fires but its bringing the rest of the original url after the guid along with it to the redirected page. Any way to insure its just the guid that gets brought over?
- VernonWells
Employee
The URI fragment above is either malformed, or the request URI was structured in an odd. Query parameters start with a question mark (?). The fragment above is, well, a fragment, because after the path, there is a hash (). This is certainly legal, but it means that everything following the hash () are not query parameters. If I substitute a question mark for the hash, this is what I get:
curl -D - 'http://10.11.210.100:8080/en/server/GUID-876D26ED-3B49-41EB-8470-78D3F60F1360?addHistory=true&filename=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357.xml&docid=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357&inner_id=&tid=&query=&scope=&resource=&eventType=lcContent.loadDocGUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357' HTTP/1.0 302 Found Location: http://host.example.com/en/server/GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357 Server: BigIP Connection: Keep-Alive Content-Length: 0Does the client really send the fragment marker () rather than the query marker (?)?
- jmartinez_44554
Nimbostratus
This is the actual link: https://livelibrary.osisoft.com/LiveLibrary/content/en/PI%20Server-v2/GUID-876D26ED-3B49-41EB-8470-78D3F60F1360addHistory=true&filename=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357.xml&docid=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357&inner_id=&tid=&query=&scope=&resource=&eventType=lcContent.loadDocGUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357
- Vernon_97235Historic F5 Account
The URI fragment above is either malformed, or the request URI was structured in an odd. Query parameters start with a question mark (?). The fragment above is, well, a fragment, because after the path, there is a hash (). This is certainly legal, but it means that everything following the hash () are not query parameters. If I substitute a question mark for the hash, this is what I get:
curl -D - 'http://10.11.210.100:8080/en/server/GUID-876D26ED-3B49-41EB-8470-78D3F60F1360?addHistory=true&filename=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357.xml&docid=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357&inner_id=&tid=&query=&scope=&resource=&eventType=lcContent.loadDocGUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357' HTTP/1.0 302 Found Location: http://host.example.com/en/server/GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357 Server: BigIP Connection: Keep-Alive Content-Length: 0Does the client really send the fragment marker () rather than the query marker (?)?
- jmartinez_44554
Nimbostratus
This is the actual link: https://livelibrary.osisoft.com/LiveLibrary/content/en/PI%20Server-v2/GUID-876D26ED-3B49-41EB-8470-78D3F60F1360addHistory=true&filename=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357.xml&docid=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357&inner_id=&tid=&query=&scope=&resource=&eventType=lcContent.loadDocGUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357
- VernonWells
Employee
And actually, I lied. The unencoded hash is NOT legal in the submitted URI path. See RFC 3986 section 3.5:
Fragment identifiers have a special role in information retrieval systems as the primary form of client-side indirect referencing, allowing an author to specifically identify aspects of an existing resource that are only indirectly provided by the resource owner. As such, the fragment identifier is not used in the scheme-specific processing of a URI; instead, the fragment identifier is separated from the rest of the URI prior to a dereference, and thus the identifying information within the fragment itself is dereferenced solely by the user agent, regardless of the URI scheme.In other words, the user-agent is supposed to strip everything from the URI path starting with the hash, and use it for object internal dereferencing (as happens, for example, in an HTML document with the use of
- jmartinez_44554
Nimbostratus
understood as the uri is generated by an application I have no control over it. :(
I logged the orig uri, the $guid and the redirect uri and this is what I'm seeing. From all appearences it should be working. If you enter the redirect uri manually into a browser it works.: /LiveLibrary/web/content.xql?c=t&pub=server-v2&lang=en&action=topic&format=html&docid=GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357&filename=&query=&scope=&tid=
: GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357
: redirecting to http://livelibrarytest.osisoft.int/LiveLibrary/content/en/server-v2/GUID-BB7DFC3D-E215-4252-AAFA-29EC2AEA5357
- VernonWells
Employee
Sorry, I posted the previous comment then saw your follow-up. Unfortunately, the URI you provide isn't really legal, and the
handling primitives are sensitive to this fact. If you cannot alter this client behavior, then it looks like you will have to bypass the HTTP events and primitives and directly read the data.HTTP::when CLIENT_ACCEPTED { TCP::collect } when CLIENT_DATA { set guid [findstr [TCP::payload] "docid=" 6 &] TCP::release } when HTTP_REQUEST { if { [info exists guid] && $guid ne "" } { HTTP::redirect "http://host.example.com/en/server/$guid" } }This assumes the entire request URI can be found in the first TCP segment. If you want it to be more robust, you'll have to expand on the logic a bit.
- jmartinez_44554
Nimbostratus
Vernon,
I want to thank you for all your help on this. Unfortunately the docid= is not part of the TCP segment. Going to put this to rest and revisit it later.
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