Appendix C: Scripts : Examples : Rewrite the HTTP request host header and path
 
Rewrite the HTTP request host header and path
You can use the content rewriting feature to rewrite the HTTP request Host header or the HTTP request URL. If you need more granular capabilities, you can use scripts. The following example rewrites the HTTP Host header and path.
-- Rewrite the HTTP Host header and path in a HTTP request
when RULE_INIT {
debug("rewrite the HTTP Host header and path in a HTTP request \n")
}
 
when HTTP_REQUEST{
host = HTTP:header_get_value("Host")
path = HTTP:path_get()
if host:lower():find("myold.hostname.com") then
debug("found myold.hostname.com in Host %s \n", host)
HTTP:header_replace("Host", "mynew.hostname.com")
HTTP:path_set("/other.html")
end
}
Note: You might find it useful to use a combination of string manipulation functions. For example, this script uses lower() to convert the Host strings to lowercase in combination with find(), which searches for the Host header for a match: host:lower():find("myold.hostname.com").