Forum Discussion

dbizzle_20930's avatar
dbizzle_20930
Icon for Nimbostratus rankNimbostratus
Oct 01, 2012

yet another redirect question

so heres my question. i have a simple irule that will redirect to a new host/uri based on the incoming request. however what i'm discovering is that apparently its not as simple as i had originally thought. i dont seem to understand why the orignial URI still gets appended to the redirected uri..

 

when HTTP_REQUEST {

 

 

 

set dest https://some.host.com/singleuri

 

 

switch -glob [string tolower [HTTP::host][HTTP::uri]] {

 

"some.other.host.com/anotheruri/*" {

 

HTTP::respond 301 Location "$dest[HTTP::uri]"

 

}

 

}

 

}

 

 

this works, yet the new uri contains "/singleuri/anotheruri/".. what am I doing wrong?

 

3 Replies

  • You are appending the previous URI which is contained in the [HTTP::uri] variable.

     

    If you just want it to goto https://some.host.com/singleuri change your redirect line to "HTTP::response 301 Location "$dest"

     

  • You'd want something like this;

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::host][HTTP::uri]] {
          "https://some.host.com/singleuri*" {
             HTTP::respond 301 Location "https://some.other.host.com/anotheruri/"
          }
          }
    }
    
  • Hi Dave,

    If you want to maintain any additional information in the [HTTP::uri] then you can just replace the host value and then perform a "string map" to replace the target values.

    Also, do not include the URI::protocol in the switch comparison.

     
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::host][HTTP::uri]] {
    "some.host.com/singleuri*" {
    HTTP::respond 301 Location "https://some.other.host.com[string map {"/singleuri" "/anotheruri"} [HTTP::uri]]"
    }
    }
    }
    

    Hope this helps.