iRule Help - Capture URI, Modify, and Redirect
I have two sets of incoming URLs I need to pick apart and redirect based on their content. Both with the same formatting.
https://my.site.org/A/B/find-a-thing1/garbage
https://my.site.org/A/B/find-a-thing1/thing1detail/actualthing1/garbage
https://my.site.org/A/B/find-a-thing2/garbage/moregarbage/additionalgarbage
https://my.site.org/A/B/find-a-thing2/thing2detail/actualthing2/garbage
"garbage" always starts with "!ut", but could have literally anything after that including additional "/" and more content. Regardless none of it is needed.
find-a-thing1 and find-a-thing2 as well as thing1detail and thing2detail will not change in their respective paths.
actualthing1 and actualthing2 will not have any consistent behavior, specific text to key off of, or common length. I need to extract their values from the URI and use them in the redirect. I'm thinking using scan may be what I need to do, but I don't have the experience to know how to write that from scratch. I don't really understand the scan function, just read from another post and modified.
I need to now validate the part where I am extracting the information from the URI. I took at stab at it, but I think I need some assistance.
when HTTP_REQUEST {
set URI [string tolower [HTTP::uri]]
if { $URI contains "find-a-thing1" and $URI contains "thing1detail"}
set actualthing1value [scan $URI {/thing1detail/%[^/]/%[^.]/!ut}]
HTTP::redirect https://new.http.host/things1/$actualthing1value
if { $URI contains "find-a-thing1"}
HTTP::redirect https://new.http.host/things1
if { $URI contains "find-a-thing2" and $URI contains "thing2detail"}
set actualthing2value [scan $URI {/thing2detail/%[^/]/%[^.]/!ut}]
HTTP::redirect https://new.http.host/things2/$actualthing2value
if { $URI contains "find-a-thing2"}
HTTP::redirect https://new.http.host/things2
}