Forum Discussion
Julian_Grunnell
Nimbostratus
Jul 24, 2008Rewriting 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.
5 Replies
- Nicolas_Menant
Employee
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 - Julian_Grunnell
Nimbostratus
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. - Nicolas_Menant
Employee
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 - Julian_Grunnell
Nimbostratus
Thanks again - not thought about using a class!! LTM is running v9.1.2 ... needs upgrading as well.
J. - Colin_Walker_12Historic F5 AccountA 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
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
