Forum Discussion
Misty_Spillers
Nimbostratus
Sep 20, 2016Rebranding website redirect question
I have to do a redirect where i thought simply this would work:
if { [string tolower [HTTP::uri]] starts_with "/" } {
HTTP::redirect "http://www.newsite.com/[HTTP::uri]"
} else {
Nothing ...
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"
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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