Forum Discussion

Brian_Kenworthy's avatar
Brian_Kenworthy
Icon for Nimbostratus rankNimbostratus
Feb 10, 2011

HTTP>HTTPS Redirect to different domain

Hi all, this should be pretty simple....hopefully.

 

 

I have a simple HTTP>HTTPS redirect in place for a domain --> HTTP::redirect "https://[HTTP::host][HTTP::uri]"

 

 

We have several subdomains (~15) xxx.domainA.com, yyy.domainA.com, etc. What we would like to do now is redirect those same sub domains to a new domain:

 

 

http://xxx.domainA.com to https://xxx.domainB.com

 

http://yyy.domainA.com to https://yyy.domainB.com

 

http://zzz.domainA.com to https://zzz.domainB.com

 

 

Is there any easier way to do this besides using a switch command for ever sub domain? I.E.

 

 

when HTTP_REQUEST {

 

switch [HTTP::host] {

 

xxx.domainA.com {

 

HTTP::redirect "https://xxx.domainB.com"

 

}

 

yyy.domainA.com {

 

HTTP::redirect "https://yyy.domainB.com"

 

}

 

etc...

 

 

Thanks in advance for the help!
  • Sure, just add the domain suffix to the redirect:

    
    when HTTP_REQUEST {
      if { [string tolower [HTTP::host]] ends_with "domaina.com" } {
        HTTP::redirect "https://[getfield [HTTP::host] "." 1].domainB.com.sg[HTTP::uri]"
      }
    }
    

    Aaron
  • What if we have multiple prefix to the domain. whill that be reditected too. For example if we have xxx.yyy.DomainA.com this does not get routed to xxx.yyy.DomainB.com with the above rule. Am i missing anythin here.
  • e.g.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set host [string tolower [HTTP::host]]
       if {$host ends_with "domaina.com"} {
          HTTP::redirect "https://[string map {"domaina.com" "domainb.com"} $host][HTTP::uri]"
        }
    }
    }
    
    [root@ve10:Active] config  curl -I http://172.28.19.79/something -H "Host: www.domaina.com"
    HTTP/1.0 302 Found
    Location: https://www.domainb.com/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve10:Active] config  curl -I http://172.28.19.79/something -H "Host: xxx.yyy.domaina.com"
    HTTP/1.0 302 Found
    Location: https://xxx.yyy.domainb.com/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0