Forum Discussion

Joe_Erchul_4263's avatar
Joe_Erchul_4263
Icon for Nimbostratus rankNimbostratus
May 15, 2012

Rewriting host and part of URI, then appending the remainder of the URI

Gang,

 

 

Trying to create an iRule to bail out my Application people. I need to modify the existing host to be a new host, then modify the "starts_with" portion of the URI, but also append the remainder of the URI for the end-user.

 

 

 

So, http://Server1/ThisURI/end-up-here.htm should rewrite to http://FinalDestination/new/end-up-here.htm

 

 

 

 

 

I've architected the following iRule that's not currently working:

 

 

 

when HTTP_REQUEST {

 

if { (([HTTP::host] equals "Server1") or ([HTTP::host] equals "Server2")) and

 

([HTTP::uri] starts_with "/ThisURI") } {

 

HTTP::header replace Host "FinalDestination"

 

HTTP::uri "/new[string range $uri 8 end]"

 

}

 

}

 

 

 

 

 

 

Any help would be much appreciated.

 

 

 

Thanks.

 

 

 

Joe

 

 

 

 

 

3 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    Joe

     

     

    Do you need to set the uri variable first?

     

     

    when HTTP_REQUEST {

     

    set uri [HTTP::uri]

     

    ......etc

     

     

    Rgds

     

    N
  • Nathan,

     

     

    Thanks for the tip. I added the variables as follows, but still no luck. I don't use variable definition much, so could you check my format for the correct syntax?

     

     

    Thanks.

     

     

    Joe

     

     

     

     

    when HTTP_REQUEST {

     

    set uri [HTTP::uri]

     

    set header [HTTP::host]

     

    if { (([HTTP::host] equals "Server1") or ([HTTP::host] equals "Server2")) and

     

    ([HTTP::uri] starts_with "/ThisURI") } {

     

    HTTP::header replace Host "FinalDestination"

     

    HTTP::uri "/new[string range $uri 8 end]"

     

    }

     

    }
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    Joe

     

     

    Without my test bed to double check things do look correct. Here's my iRule with a slight amendment to rule out case insensitivities:

     

     

    when HTTP_REQUEST {

     

    switch [string tolower [HTTP::uri]] {

     

    set uri [HTTP::uri]

     

    if { (([HTTP::host] equals "Server1") or ([HTTP::host] equals "Server2")) and

     

    ($uri starts_with "/ThisURI") } {

     

    HTTP::header replace Host "FinalDestination"

     

    HTTP::uri "/new[string range $uri 8 end]"

     

    }

     

    }

     

    }

     

     

    What happens if you do a curl -i http://Server1/ThisURI/end-up-here.htm -what response do you get back?

     

     

    N