Handling www with host name redirects in iRule
I'm trying to figure out how I can handle the following situation.
The section of the iRule below is for redirecting to a different URL based on a hostname. Our organization has purchased multiple domain names that are more or less used as shortcuts to a specific URL.
For example: companydepartment.com -> http://www.company.com/department/index.html
I'm using data groups to facilitate this with a name -> value in a string data group. In trying to optimize the code for this, I've ran into a snag when they want to use www.companydepartment.com.
I have to create a duplicate entry for www.companydepartment.com -> http://www.company.com/department/index.html
How can I handle this traffic so that both hostname with and without www. will be matched, and also with the understanding that there may be a subdomain to a different URL in some cases www.training.companydepartment.com -> http://www.company.com/department/training.html
if {[class match [HTTP::host] eq group_80_host_redirect]} {
HTTP::redirect [class match -value [HTTP::host] eq group_80_host_redirect]
}
Data group example
ltm data-group internal group_80_host_redirect {
records {
company.com {
data http://www.company.com
}
companydepartment.com {
data http://www.company.com/department/index.html
}
training.companydepartment.com {
data http://www.company.com/department/training.html
}
}
type string
}