Forum Discussion
smiley_dba_1116
Nimbostratus
Jun 28, 2010HTTP 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.
6 Replies
- Chris_Miller
Altostratus
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
Cirrostratus
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 - smiley_dba_1116
Nimbostratus
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? - smiley_dba_1116
Nimbostratus
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"] - Michael_Yates
Nimbostratus
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
Cirrostratus
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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
