Redirect rewrite iRule

I’m trying to craft an irule to do the following: If user hits site-1 and has /europe/[HTTP::uri], redirect him to site-2, remove /europe and add /america, and append trailing URI of the initial request.

when HTTP_REQUEST {

if {[HTTP::host] == www.site-1.com && [HTTP::uri] == “/europe/[HTTP::uri]” } {

HTTP::redirect "www.site-2.com/america/[HTTP::uri] }

}

Hi VFB,

You can use string map for string replacement.

https://devcentral.f5.com/s/articles/irules-101-14-tcl-string-commands-part-2

when HTTP_REQUEST {
	if { [HTTP::host] equals "www.site-1.com" && [HTTP::uri] starts_with "/europe/" } {
		HTTP::redirect "https://www.site-2.com[string map {/europe/ /america/} [HTTP::uri]]"
		return
	}
}