Forum Discussion
You could use getfield function to grep host name.
iRule will be some thing like below. Paste the comments if any help require.
when HTTP_REQUEST {
if { [HTTP::host] contains "test.com"} {
HTTP::respond 301 Location "https://[getfield [HTTP::host] ".test.com" 1].result.com[HTTP::uri]
}
}
Cheers...
Hi, I have prepared the below script for an URL redirection based on host name with top level domain value. Can you please advise whether I have made any error or any where I have to change the logic?
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with ".testold1.com"}{ set newurl [string map -nocase {".testold1.com" ""}[HTTP::host] ".testnew.com" 1] HTTP::respond 301 Location "http://.[HTTP::host $ newurl][HTTP::uri] } else if {[string tolower [HTTP::host]] starts_with ".testold.com"}{ set newurl [string map -nocase {".testold.com" ""}[HTTP::host] ".testnew.com" 1] HTTP::respond 301 Location "http://.[HTTP::host $ newurl][HTTP::uri] } }
OR
when HTTP_REQUEST { if { ([HTTP::host] contains ".testold1.com") { HTTP::respond Location 301 "https://[getfield [HTTP::host] ".testold1.com" 1].testnew[HTTP::uri] } else if { ([HTTP::host] contains ".testold2.com") { HTTP::respond Location 301 "https://[getfield [HTTP::host] ".testold2.com" 1].testnew[HTTP::uri] } }