Martin_Thomas_1
Dec 04, 2013Nimbostratus
Replace part of HTTP::host and permanently redirect
I'm looking at redirecting various hosts to a new domain.
Example 1: app.olddomain.com to app.newdomain.com Example 2: anotherapp.olddomain.com to anotherapp.newdomain.com
The problem I'm having (because I'm a newb with string manipulation) is switching that "olddomain" to the "newdomain".
I could do the following for each of the applications but it would mean a huge iRule:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "app.olddomain.com" } {
HTTP::respond 301 Location "https://app.newdomain.com[HTTP::uri]"
}
}
I was hoping to do something like this:
when HTTP_REQUEST {
if {[HTTP::host] ends_with ".olddomain.com"} {
HTTP::respond 301 Location "https://--part of original host--.newdomain.com[HTTP::uri]"
}
}
Is my idea sound? How do we accomplish the replace?
Thanks!
Either (this is probably more efficient);
when HTTP_REQUEST { if {[HTTP::host] ends_with ".olddomain.com"} { HTTP::respond 301 Location "https://[getfield [HTTP::host] . 1].newdomain.com[HTTP::uri]" } }
Or;-
when HTTP_REQUEST { if {[HTTP::host] ends_with ".olddomain.com"} { HTTP::respond 301 Location "https://[string map {olddomain newdomain} [HTTP::host]][HTTP::uri]" } }