Help with an I-rule rewrite
I'm trying to use an I-rule to add the http hostname in the url to the beginning of the uri then rewrite the hostname. Example:
If the client request to a VIP is https://proxy-v2.api-np-c.newapps.com/<somepath>, I want the request to the server pool to be this https://proxy-v2.api-gw-np-a.newapps.com/proxy-v2.api-np-c.newapps.com/<somepath>
I've tried this and it didn't work:
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/" } {
HTTP::uri /[HTTP::host][HTTP::uri]
}
switch -glob [HTTP::host] {
"*.api-np-c.newapps.com*" {
set http_host [HTTP::host]
set startPos [string first .api-np-c $http_host]
set endPos [expr $startPos + 11]
set http_host [string replace $http_host $startPos $endPos .api-gw-np-a]
HTTP::header replace Host "$http_host"
}
}
}
-------------------------------------------------------------------------------------------------------
After some digging, I plan to try this next:
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/" } {
HTTP::uri /[HTTP::host][HTTP::uri]
} else {
switch -glob [HTTP::host] {
"*.api-np-c.newapps.com*" {
set http_host [HTTP::host]
set http_host [string map -nocase {".api-np-c" ".api-gw-np-a"} [HTTP::uri]]
HTTP::header replace Host "$http_host"
}
}
}
}
As you can probably tell, I'm really new working with i-rules. Any help would be greatly appreciated!