Forum Discussion

Rodney_Newton_7's avatar
Rodney_Newton_7
Icon for Nimbostratus rankNimbostratus
Nov 08, 2006

Change Host Value

All,

 

 

I am trying to do something I thought would be pretty simple but I am missing something... whenever I see a request for www.outsidedomain.com I need to change that to servername. When I see the response I need to flip it the other way. Here is what I tried but maybe I am going about this the wrong way.

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "www.outsidedomain.com" }{

 

HTTP::header replace host "servername"

 

log local0. "The header is [HTTP::header host] "

 

log local0. "The Host Value is [HTTP::host]"

 

} else {

 

log local0. "No Changes Made"

 

}

 

}

 

 

The HTTP::host entry in the log is the same as when it came in but the HTTP::header host is the value I set. I understand that I need a when HTTP_RESPONSE for the return traffic but I can't even get this first part to work. What am I doing wrong? Thanks.

2 Replies

  • I've seen in other posts that you can set the host itself with the HTTP::host command, though it doesn't appear to be supported in my version (9.1.2)

    
    when HTTP_REQUEST {
      if { [HTTP::host] equals "www.outsidedomain.com" }{
        HTTP::header replace host "servername"    HTTP::host "servername"
        log local0. "The header is [HTTP::header host] "
        log local0. "The Host Value is [HTTP::host]"
      } else {
        log local0. "No Changes Made"
      }
    }
  • I also thought 'HTTP::host mynewhost.example.com' would work, but it doesn't on 9.2.3 either.

    I think the value of HTTP::host is cached so you don't see the updated value when setting the host header value with 'HTTP header replace Host newhost.example.com', but the value is actually changed. [HTTP::header Host] apparently isn't cached and therefore shows the correct value.

    Regardless, you should be able to confirm by checking the HTTP data sent from the BIG-IP to the node using tcpdump or looking at the node's web server logs.

    As for rewriting the responses:

    If the web application is sending absolute references which include the internal domain, you could use a stream profile to rewrite oldhost.example.com in the HTTP content.

    If you need to rewrite the domain in redirects, you could use a rule (the stream profile won't operate on HTTP headers). Here is an example:

    
    when HTTP_RESPONSE {
       if {[HTTP::is_redirect]}{
          HTTP::header replace Location [string map { "oldhost.example.com" "newhost.example.com" } [HTTP::header value Location]]
       }
    }

    Aaron