We host many of our sites as .org but still register the .com and .net domains. We’d like to have a single VIP that takes any “requested_domain.com” and rewrites it to “requested_domain.org”. Currently we use a rule that I found on this site by Denny Payne:
This works great however every time we add another domain we have to modify the iRule. I’d like to create one that works on any request.
If it were to turn mysite.com into a string that it could strip off the .com from and then add a .org to the end redirecting to the new string it would be perfect however I’m not sure how to manipulate strings like that in the iRules world.
I think you could do this with string commands more efficiently:
when HTTP_REQUEST {
Check if host doesn't end with .org and has at least one alpha character
if { not ([string tolower [HTTP::host]] ends_with ".org") and [string match {[a-zA-Z]} [HTTP::host]] }{
Redirect to the same host with the last three characters removed and org added
HTTP::redirect "http://[string range [HTTP::host] 0 end-3]org[HTTP::uri]"
}
}
The solution provided by hoolio seemed to not work correctly, perhaps it directed the user in circles because of our setup.
The solution from Michael worked just perfectly. I modified it to actually do the same for both .com and .net redirecting to the https .org equivalent.