Forum Discussion
crodriguez
Sep 20, 2016Ret. Employee
Your "if" condition will always match, as URI always starts with a "/" - even when the user doesn't actually provide anything after the host name. (Browser's insert the "/" even if nothing follows host name.) So that's not an effective test to see if there is something more than just the host name. Since it's unclear just when you actually want to redirect, I'll focus on the part where you want to capture just the "randomuri" part of the URI and ditch the "/whatever..." part. For example:
Assume HTTP::uri contains "/randomuri/whatever..."
Assume redirect is to occur using only the first subdirectory portion of the URI
(in other words, just the "randomuri" part)
set directory [getfield [HTTP::uri] "/" 2]
HTTP::redirect "http://www.newsite.com/$directory"