Forum Discussion

WestonBlake_700's avatar
WestonBlake_700
Icon for Nimbostratus rankNimbostratus
May 10, 2013

Rewrite URL on Request, and then Rewrite URL on response

Hi All,

 

 

We have several country specific urls tied to the same VIP. Our sever is designed to accept connection on an internal url (internalurl.com for the example below) and produce country specific content according to the added HTTP header (bla_site) I am trying to take a request for these urls, rewrite them to the internal URL with an added HTTP header that = the original url set as a variable ($header2). Once that has been processed by the server, rewirite the outgoing url back to the original URL the customer requested. I can get this to work with 1 url, but as soon as I introduce the variable, it doesn't seem to work.

 

Here is what I have so far:

 

 

 

when HTTP_REQUEST {

 

set header_host [string tolower [HTTP::host]]

 

HTTP::header insert bla_site $header2

 

HTTP::header replace Host internalurl.com

 

 

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

 

default { DEFAULT_POOL

 

pool pool_Default

 

}

 

}

 

}

 

 

when HTTP_RESPONSE {

 

if { [HTTP::is_redirect] }{

 

HTTP::header replace Location [string map [ list internalurl.com $header2 ] [HTTP::header Location]]

 

set location $header2

 

}

 

}

 

 

Hopefully this is descriptive enough to make sense. Thanks

 

7 Replies

  • You don't appear to be setting variable 'header2' anywhere. This should help;

    
    when HTTP_REQUEST {
        set header2 [string tolower [HTTP::host]]
        HTTP::header insert bla_site $header2
    
  • Thanks for noticing that. I changed the following line:

     

    set header2 [string tolower [HTTP::host]]

     

    It is still coming out of the F5 with the internalurl.com

     

  • Sorry in the request, so now it looks like this:

     

     

    when HTTP_REQUEST {

     

    set header2 [string tolower [HTTP::host]]

     

    HTTP::header insert bla_site $header2

     

    HTTP::header replace Host internalurl.com

     

     

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

     

    default { DEFAULT_POOL

     

    pool pool_Default

     

    }

     

    }

     

    }

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::is_redirect] }{

     

    HTTP::header replace Location [string map [ list internalurl.com $header2 ] [HTTP::header Location]]

     

    set location $header2

     

    }

     

    }

     

  • OK, so it looks good. How are you confirming it's not changed? A tcpdump would prove things one way or another.
  • ok, Update, The above irule works like it should. I found an server in the mix that was stripping the headers. Thanks for the input. I guess I just needed a sanity check on my irule