Forum Discussion
hooleylist
Jun 28, 2011Cirrostratus
Hi Greg,
You can use the string range, getfield or scan command to parse the subdomain from a host header value:
when HTTP_REQUEST {
Check for a non-null length host header
if {[string match {*[a-zA-Z]*} [HTTP::host]]}{
Use string commands to parse the subdomain
set subdomain [string range [HTTP::host] 0 [expr {[string first . [HTTP::host]] -1}]]
Use the getfield command to parse the subdomain
set subdomain [getfield [HTTP::host] . 1]
Use scan to parse the subdomain
scan [HTTP::host] {%[^.]} subdomain
}
}
I'd guess that getfield is probably the simplest and potentially the most efficient option to do this.
Aaron