cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect rewrite iRule

VFB
Cirrus
Cirrus

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] }

}

1 ACCEPTED SOLUTION

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 } }

 

View solution in original post

1 REPLY 1

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 } }