Forum Discussion
hooleylist
Sep 24, 2010Cirrostratus
Can you provide a bit more detail on your requirements? Do you always want to send a redirect to one hostname (like www.example.com) if the client makes a request with a hostname that isn't www.example.com? Or are there multiple domains that clients could request which resolve to the same virtual server IP address? If there are multiple, do you always want to take the last two domain parts from the request and add www. to the front to form the host in the redirect?
As for the latest example you posted:
You can only check one string against another string using starts_with. So you can change this:
if {[HTTP::host] starts_with "www10." or "www3."} {
to:
if {[HTTP::host] starts_with "www10." or [HTTP::host] starts_with "www3."} {
Or you could use a switch statement instead:
switch -glob [string tolower [HTTP::host]] {
"www3.*" -
"www10.*" {
HTTP::respond 301 Location "http://www.[domain [HTTP::host] 2][HTTP::uri]"
}
}
And you shouldn't need to use concat with the output from the domain command. domain [HTTP::host] 2 should return the last two fields of the domain delineated by periods. So you can change this:
set key "[concat [domain [HTTP::host] 2]]"
HTTP::respond 301 Location "http://www.$key[HTTP::uri]"
to:
HTTP::respond 301 Location "http://www.[domain [HTTP::host] 2][HTTP::uri]"
Aaron