Forum Discussion
winifred_corbet
Nimbostratus
Jan 24, 2011Replace HOST not working
We have a list of URIs that we added to a data group
For only those URIs in the datagroup, we need to change the Hostname, keeping the URI
This irule attempt is not working. Host name is not changing. What are we missing?
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::uri]] starts_with $::abunchofURLs] } {
HTTP::header replace Host "www.brand-new-name.com"
}
}
4 Replies
- winifred_corbet
Nimbostratus
Datagroup:
/article/0,7120,s6-238-275-559-1141-0,00.html
/article/0,7120,s6-238-275-559-12461-0,00.html
We need the client to see the new hostname.
we did see the log entry,but host name change is not occurring. - Chris_Miller
Altostratus
So, if your rule looks like the below, you're actually seeing the log show up?when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] starts_with $::abunchofURLs] } { HTTP::header replace Host "www.brand-new-name.com" log local0. "URI was [HTTP::uri] and host was changed from [HTTP::host] to "www.brand-new-name.com" } } - Colin_Walker_12Historic F5 AccountTo be clear, you're just looking to replace the host header, not actually redirect the user so that the browser's URL bar updates, right? If you re-write the host header on the LTM the request should arrive at the correct location but the user will not see the change to the host.
Quoting the wiki Click Here:
"To update the Host header value without redirecting the client to the new Host value, you can use HTTP::header replace Host "newhost.example.com". This update will only affect the request to the pool member. The client will not see the update unless the web application uses the requested host header value to generate response headers and/or content."
Colin - hoolio
Cirrostratus
A few related possibilities:
- Are you checking the serverside connection to see the change? As Colin mentioned, the change would be made in the request which LTM proxies to the pool member. If you want the client to see the change, you could use HTTP::redirect to send a redirect instead of rewriting the proxied request's host header.
- If you're on 9.4.4 or higher, you should remove the $:: prefix from the class name reference in the iRule. In 10.x, this would break the matching.
- The value for HTTP::host and most other HTTP commands is cached in the same event and event priority. So if you log the value for HTTP::host, change it with HTTP::header replace newhost.example.com, and then log the value for HTTP::host again, the cached value will be logged.
Aaron
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