Forum Discussion
Rebranding 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 is simple I find out.
The first part of the uri (between the first /???/) always matches but everything else is different. I was wondering if there is a way to do this.
In other words
the user goes to www.oldsite.com/randomuri/whatever
They would be redirected to www.newsite.com/randomuri
I know I can make a rule for each of them, I was just hoping I wouldn't have to.
2 Replies
- crodriguezRet. 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" - TayF5un
Nimbostratus
you can add log line after the condition then you can see the uri so you can decide to what you want.
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