I have about 10 domains pointing to my Heroku app (it took forever to settle on a name for the site -- don't ask), all of which I've given to various people at various times.
Now that I've decided on a domain name (call it "example.com"), I want the existing domains to all work, but to redirect to example.com. What's the best way to do this?
Here's my approach (in application_controller.rb
):
before_filter :ensure_domain
def ensure_domain
canonical_domain = 'example.com'
if request.env['HTTP_HOST'] != domain && ENV["RAILS_ENV"] == 'production'
redirect_to request.protocol + canonical_domain + request.env["REQUEST_URI"]
end
end
Is this the right approach?