Forum Discussion
URL redirect with 301 from old host name to new host name for many URLs
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] } }
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
