Forum Discussion

Martin_Thomas_1's avatar
Martin_Thomas_1
Icon for Nimbostratus rankNimbostratus
Dec 04, 2013

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 ...
  • IheartF5_45022's avatar
    Dec 05, 2013

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