Forum Discussion
hooleylist
Apr 01, 2014Cirrostratus
Can you try a combined version?
when HTTP_REQUEST {
'root domain redirect'
if { [HTTP::host] eq "mydomain.com" } {
HTTP::respond 301 Location http://www.mydomain.com[HTTP::uri]
} elseif { [set redir [class lookup [string tolower [HTTP::uri]] equals REDIRECTS_301_SCO]] ne "" } {
HTTP::respond 301 Location $redir
} elseif { "[HTTP::host][HTTP::uri]" eq "asia.mydomain.com/taiwan" } {
HTTP::redirect http://www.mydomain.com/something
} elseif { "[HTTP::host][HTTP::uri]" eq "asia.mydomain.com/hongkong" } {
HTTP::redirect http://www.mydomain.com/something
} elseif { "[HTTP::host][HTTP::uri]" eq "asia.mydomain.com/china" } {
HTTP::redirect http://www.mydomain.com/something
} elseif { [HTTP::host] contains "asia.mydomain.com" } {
HTTP::redirect http://www.mydomain.com
} else {
Always need to remove any existing XFF headers.
if {[HTTP::header exists X-Forwarded-For]}{
HTTP::header remove X-Forwarded-For
}
If the ‘True-Client-IP’ header exists use it, otherwise just use client address.
if {[HTTP::header exists True-Client-IP]}{
HTTP::header replace X-Forwarded-For [HTTP::header value True-Client-IP]
} else {
HTTP::header replace X-Forwarded-For [IP::client_addr]
}
}
}
There were a few issues:
- Tcl error from trying to issue a redirect and insert an HTTP header for the same request
- [HTTP::request] returns all the HTTP headers of a request. I think you want the host header value and the URI so I used [HTTP::host][HTTP::uri] and removed the protocol from the strings you were checking
- == should be used for numeric comparisons. Use eq for string comparisons.
- You can save the output from class lookup instead of running two commands
Aaron