Tom_K_185554
Dec 28, 2017Nimbostratus
Solved
Need to parse the [HTTP::uri] and modify it for a redirect
Hello - I found a really useful irule from Joe Pruitt for parsing the uri
`when HTTP_REQUEST {
log local0. "‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐"
log local0. "URI Information"
log l...
- Dec 29, 2017
could you please explain what exactly the code is doing especially the regular expression part and the string map ?
/~ is literal chars (i.e. it matches /~)
%[^/] matches every chars but not / and the matching string will be stored in variable specified later (e.g. it matches geverest and geverest will be stored in first variable)
[scan [HTTP::uri] {/~%[^/]} first] returns number of matching string. so, we can use it to determine whether it is uri we are interested (i.e. 1).
[string map "/~$first/ /" [HTTP::uri]] replace /~$first/ with / in uri (e.g. it replaces /~geverest/ with /).
[root@bip1a:Active:In Sync] config tclsh % set uri "/~geverest/home/data-modeling-course/course-flyer" /~geverest/home/data-modeling-course/course-flyer % scan $uri {/~%[^/]} first 1 % put $first geverest % string map "/~$first/ /" $uri /home/data-modeling-course/course-flyer