Forum Discussion
Rewrite host header to specific pool member
I've done basic host header rewrites rules in the past but I've just received an odd request that's beyond me. I'm scrapping together a solution from multiple posts but haven't got anything to pass yet.
Our developers want the F5 to receive the URL "ims.services.company.com" and rewrite the host header to reflect the specific pool member, after the node is selected by the LB algorithm. To the point, they want the client to send the GET with "ims.services.company.com" in the host header and the F5, serverside, to send a GET for "ims.services..company.com" in the header.
I've tried this with combinations of HTTP_REQUEST, LB_SELECTED, and HTTP_REQUEST_SEND but nothings working.
I'm assuming this can be done?
Thanks.
- hoolio
Cirrostratus
Hi,when HTTP_REQUEST { Set the Host header to www.example.com HTTP::header replace Host "www.example.com" }
From: http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP_REQUEST_SEND when HTTP_REQUEST_SEND { Need to force the host header replacement and HTTP:: commands into the clientside context as the HTTP_REQUEST_SEND event is in the serverside context clientside { Replace the HTTP host header with the selected server IP and port HTTP::header replace Host "[LB::server addr]:[LB::server port]" } }
- astokes_6920
Nimbostratus
Thanks. That's a really good start. Wireshark (on the serverside) shows the IP address:port in the header "Host: 10.200.32.80\r\n" - nitass
Employee
not sure if i understand correctly. pls feel free to revise.v10.1.0 virtual bar { snat automap pool foo destination 172.28.17.55:http ip protocol tcp rules myrewrite profiles { http {} tcp {} } } pool foo { members { 10.10.70.110:http {} 10.10.70.120:http {} 10.10.70.130:http {} } } class myhost { { "10.10.70.110" { "node1" } "10.10.70.120" { "node2" } "10.10.70.130" { "node3" } } } rule myrewrite { when HTTP_REQUEST_SEND { clientside { if {[HTTP::host] equals "172.28.17.55"} { HTTP::header replace Host "[class match -value [LB::server addr] equals myhost]" } } } }
client side: GET / HTTP/1.1 Host: 172.28.17.55 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive server side: GET / HTTP/1.1 Host: node3 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive
- astokes_6920
Nimbostratus
I think I'm really close now. With the following, I get the following error: Line 4 [undefined procedure: class] - nitass
Employee
i understand in v9 u've to use findclass. the class command is available in v10. - hoolio
Cirrostratus
Here's a 9.x rule for this: - astokes_6920
Nimbostratus
Cool. - hoolio
Cirrostratus
You can add the string datagroup element exactly like this in the GUI: - astokes_6920
Nimbostratus
Voila. According to wireshark: - hoolio
Cirrostratus
Glad that's working for you. If doing just this Host header rewrite works, I wouldn't suggest using the ProxyPass iRule. That rule provides a lot more functionality--and overhead--that you probably don't need.
Recent Discussions
Related Content
* 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