Forum Discussion

Julian_Grunnell's avatar
Julian_Grunnell
Icon for Nimbostratus rankNimbostratus
Jul 24, 2008

Rewriting HOST header

Hi - can someone offer some help, I've got a request to do some header rewriting and have a rough idea of how to do this but hoping someone has done this before!!

 

 

I need to have an iRule that takes a request such as www.site1.com and sends to the www_pool and requests for admin.site1.com goto the admin_pool. Now this is pretty straightforward BUT is there a way that once I've determined that the request is for a host that starts with "admin" I can rewrite the host header to www.site1.com for example and STILL send to the admin_pool?

 

 

Also the number of unique sites is around 160 at present with more being adding, around 10 a month.

 

 

Thanks in advance - Julian.
  • Hi,

    To simply rewrite the host header you can use this command:

     
     HTTP::header replace Host www.site1.com 
     

    This command will simply rewrite the host header and not make new routing decision

    HTH
  • Hi - thanks, should have said as well I see that will work but when I have 160 sites to start with and more being added is there a better way to do this? I don't fancy having 160+ replace statements.

     

     

    J.
  • Hi,

    To make it easier you should specify a class that will specify for each host, what should be the replacement value and then use the command findclass

    You can find a reference to this command here: Click here

    It would look like this (the class define below should be define as a datagroup)

      
      class dest_pairs {  
        " proxy"  
        "admin.site1.com www.mysite.com"  
        "admin.site2.com www.mysite2.com"  
      }  
        
      when CLIENT_ACCEPTED {  
        set my_dest [findclass [HTTP::host] $::dest_pairs " "]  
        if { $my_destl ne "" } {  
          HTTP::header replace Host $my_dest  
        }  
      }  
        
      

    If you have a BIGIP 8XXX you should replace $::dest_pairs by ::dest_pairs in order not to demote CMP. (you need to have a v9.4.2 version to do so)

    HTH
  • Thanks again - not thought about using a class!! LTM is running v9.1.2 ... needs upgrading as well.

     

     

    J.
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    A class or a switch are definitely the cleanest way to achieve this. A class is easiest for updating on a more regular basis, a switch is a little bit faster if you're going to be setting this once and leaving it alone.

     

     

    Colin