Forum Discussion

Pete_Paiva_7147's avatar
Pete_Paiva_7147
Icon for Nimbostratus rankNimbostratus
Aug 23, 2013

URL hostname rewrite

Got a question from one of my application owners in regards to Remedy (BMC Software). They're looking to have the LTM do the following:

 

  1. User types in URL http://support.mycompany.com

     

  2. Traffic gets load balanced to a server in the pool, in this example server1

     

Is it possible to have the URL modified to show http://server1.mycompany.com instead of http://support.mycompany.com

 

Any help would be greatly appreciated - thanks!!

 

4 Replies

  • Sure can. If you just want to change the host header sent to your backend server while maintaing the support.mycompany.com to your end users, just use the HTTP::header command to change the host header. Something like this should work

    when HTTP_REQUEST {
      if { [HTTP::host] eq "support.mycompany.com" } {
        HTTP::header replace "Host" "server1.mycompany.com"
      }
    }
    

    The "if" check on the host is only in case you are multi-hosting this iRule. If you want to unconditionally change the host value sent back to the server, you can just use the HTTP::header replace command by itself.

    Keep in mind though that if you pass a host value to the back end app server, that some app servers may generate page links based on the passed in host header. If your app did this, you'd have to have a DNS entry for server1.mycompany.com that goes to your VIP.

    If you want to do a redirect (which is not what it sounds like you want, you can do a simple redirect

    when HTTP_REQUEST {
      if { [HTTP::host] eq "support.mycompany.com" } {
        HTTP::redirect "http://server1.mycompany.com[HTTP::uri]"
      }
    }
    

    Hope this helps...

    -Joe

  • You should just need to change the Host header in the request. Example:

    when HTTP_REQUEST {
        HTTP::header replace Host "server1.mycompany.com"
    }
    
  • Guys, this is great thanks for the quick reply!!

     

    In this case we have 8 servers in the pool so how can I create the iRule so it works depending on the specific pool member?

     

  • Two options:

    1. You could maintain a data group that maps the name to the IP. Example:

      datagroup (ex. my_server_dg):
      
      10.10.42.10 := server1.domain.com
      10.10.42.11 := server2.domain.com
      10.10.42.12 := server3.domain.com
      
      iRule:
      when HTTP_REQUEST_SEND {
          clientside {
              HTTP::header replace "Host" [class match -value [LB::server addr] equals my_server_dg]
          }
      }
      
    2. If you have internal DNS you could do a quick reverse lookup to get the name.