Forum Discussion
Chris_Day_10331
Nimbostratus
Jan 04, 2006Can this redirect rule be optimized?
Hey guys,
I created a pretty basic/lame redirect rule and I thought I'd post it to see if anyone had any recommendations on how to optimize it. I'll paste the goods first since I think it basicall...
Jan 04, 2006
Using a switch is one of the most optimal ways to do this. But if, as you said, you foresee manageability issues with the large number of domains across multiple virtuals, then you could do it with data groups. Here's an alternate implementation using a string datagroup with the domain mapping contained in the data group.
class domain_mappings {
"domain.ca domain.myasp.com"
"domain.com domain1.myasp.com"
"domain.biz domain2.myasp.com"
"joe.com domain3.joe.com"
"fred.us domain4.fred.com"
}
when HTTP_REQUEST {
Extract the domain portion of the host
set valid_domain [regexp {\.([\w]+)\.([\w]+)$} [HTTP::host] domain company ext]
if { $valid_domain }
{
Look for match in the domain_mappings data group
set new_domain [findclass "$company.$ext" $::domain_mappings " "]
if { "" ne $new_domain } {
Issue redirect
HTTP::redirect http://$new_domain[HTTP::uri]
}
}
}
There's probably some more optimal way to extract only the last two tokens from the host aside from a regexp but this should account for any type of host you specify (www.foo.com, www1.www.foo.com, etc).
So, with this option, you would either maintain a single master domain_mappings list and apply the same iRule across all of your virtuals, or split out the domain_mappings data group into smaller more manageable ones. Your choice.
*disclaimer: This is probably lower performance than your switch option, but it is a much simpler version for when you scale to a larger format.
-Joe
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