Forum Discussion

Misty_Spillers's avatar
Misty_Spillers
Icon for Nimbostratus rankNimbostratus
Sep 20, 2016

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

  • 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"
    
  • you can add log line after the condition then you can see the uri so you can decide to what you want.