Forum Discussion

dsirrine_24840's avatar
dsirrine_24840
Icon for Altostratus rankAltostratus
Aug 18, 2009

subdomain redirect question

Issue: I have a domain foo.com. foo.com and www.foo.com need to be redirected to www.bar.com/foo. However, users.foo.com needs to be redirected to sub.bar.com/account/login. My irules look as such:

 

 

when HTTP_REQUEST {

 

if {[HTTP::host] eq "users.foo.com"} {

 

HTTP::respond 301 Location "http://sub.bar.com/account/login/"

 

}

 

elseif {[HTTP::host] contains "foo.com"} {

 

HTTP::respond 301 Location "http://www.bar.com/foo"

 

}

 

 

When I go to foo.com or www.foo.com it will redirect to http://www.bar.com/foo. However, when I go to users.foo.com, it doesn't go to http://sub.bar.com/account/login but rather goes to http://www.bar.com/foo. Is there a special way to do this? Thanks in advance.

1 Reply

  • Hi,

    That looks OK to me, you can try adding logging to see if the host is really showing up as you expect:

     
     when HTTP_REQUEST { 
        if {[HTTP::host] eq "users.foo.com"} { 
          log local0. "Found users in [HTTP::host]" 
          HTTP::respond 301 Location "http://sub.bar.com/account/login/" 
     } 
        elseif {[HTTP::host] contains "foo.com"} { 
        log local0. "Did not find users in [HTTP::host]" 
        HTTP::respond 301 Location "http://www.bar.com/foo" 
     }  
     

    The logs will show up in /var/log/ltm.

    Denny