Forum Discussion

smiley_dba_1116's avatar
smiley_dba_1116
Icon for Nimbostratus rankNimbostratus
Jun 28, 2010

HTTP header redirect

V.10.2

 

 

Having a issue when trying to do a redirect. When a client types in www.xxx.com, we want the load balancer to look at the header, and auto redirect to www.yyy.com. Currently, I tried to use the following:

 

 

when HTTP_REQUEST {

 

if { ([HTTP::host] != "www.xxx.com") } {

 

HTTP::redirect "http://www.yyy.com"

 

}

 

}

 

 

I does not redirect at all. it just sits there. Any help is great appreciated.

 

  • Posted By smiley_dba on 06/28/2010 09:18 AM

    V.10.2

    Having a issue when trying to do a redirect. When a client types in www.xxx.com, we want the load balancer to look at the header, and auto redirect to www.yyy.com. Currently, I tried to use the following:

    when HTTP_REQUEST {

    if { ([HTTP::host] != "www.xxx.com") } {

    HTTP::redirect "http://www.yyy.com"

    }

    }

    I does not redirect at all. it just sits there. Any help is great appreciated.

    You're basically trying to do a host redirect. You've used the "!" character which basically = "not" so you're saying if your host doesn't equal "www.xxx.com" then redirect to www.yyy.com" Remove the "!" and see what happens.
    when HTTP_REQUEST { 
      if { ([HTTP::host] eq "www.xxx.com") } {
        HTTP::redirect "http://www.yyy.com"
      }
    }
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Or maybe you could change the rule to check if the host isn't www.yyy.com redirect to www.yyy.com? Either way, adding debug logging is a good way to figure out what code is executing:

     

     

    
    when HTTP_REQUEST {
    
       log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"
    
       if { ([HTTP::host] != "www.yyy.com") } {
          log local0. "[IP::client_addr]:[TCP::client_port]: Matched host check, redirecting."
          HTTP::redirect "http://www.yyy.com"
       }
    }
    

     

     

    Aaron
  • Received an error:

     

     

    01070151:3: Rule [xxx_to_yyy_yyyy.com_Redirect] error: line 3: [wrong args] [HTTP::redirect "yyyy.com" target="_blank" rel="nofollow">"yyy.com"]

     

     

    Did i miss a carrot?
  • Tried the

     

     

     

    when HTTP_REQUEST {

     

    if { ([HTTP::host] eq "www.xxx.com") } {

     

    HTTP::redirect "http://www.yyy.com" target="_blank" rel="nofollow">http://www.yyy.com"

     

    }

     

    }

     

     

    But received the error

     

     

     

    01070151:3: Rule [xxx_to_yyy_yyyy.com_Redirect] error: line 3: [wrong args] [HTTP::redirect "yyyy.com" target="_blank" rel="nofollow">"yyy.com"]

     

  • The Rule that is giving you an Error doesn't have your previous "if not" matching requirement.

    Try this:

    
    when HTTP_REQUEST { 
    if { !([HTTP::host] equals "www.xxx.com") } {
    HTTP::redirect "http://www.yyy.com"
    HTTP::respond 301 Location "http://www.yyy.com"
    }
    }
    

    HTTP::redirect - gives a 302 Temporary Redirect

    HTTP::respond 301 Location - gives a 301 Permanent Redirect.
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus

     

    01070151:3: Rule [xxx_to_yyy_yyyy.com_Redirect] error: line 3: [wrong args] [HTTP::redirect "yyyy.com" target="_blank" rel="nofollow">"yyy.com"]

     

     

     

    The DC forum code is breaking the code blocks by incorrectly autolinking anything starting with http://. Everything after the second double quote in the line is errant and should be removed (target="_blank" rel="nofollow">http://www.yyy.com").

     

     

    Michael's latest post should give you some valid examples.

     

     

    Aaron