
Host and URL Rewrite, Content Matching and Redirecting
Below are some example iRules used for redirecting and rewriting URL and Host Headers.
Rewrites
Rewrite Hostname in HTTP Request
when HTTP_REQUEST { if { [HTTP::host] equals "domain.com" } { HTTP::header replace "Host" "newdomain.com" }}
Rewrite URL in HTTP Request
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/sometext" } { HTTP::uri "/newtext" }}
Rewrite Hostname in Response
when HTTP_RESPONSE { if { [HTTP::host] equals "domain.com" } { HTTP::header replace "Host" "newdomain.com" }}
Redirects
Redirect based on URL used
when HTTP_REQUEST { if { [HTTP::uri] equals "domain.com" } { HTTP::redirect "http://www.newdomain.com/index.htm" }}
Redirect based on Hostname used
when HTTP_REQUEST { if { [HTTP::host] starts_with "/sometext" } { HTTP::redirect "http://www.newdomain.com/index.htm" }}