What's the canonical way to do a 301 redirect from any url which has www at the beginning to the root domain name - www.domain.com (or www.domain.com/something) to domain.com? And assuming there's also sub1.domain.com and, of course, there shouldn't be a redirect.
Is it before_filter in ApplicationController or something else?