title: rails in-app redirect from root/apex to www
body: <p>Because of Heroku's apex domain <a href="https://devcenter.heroku.com/articles/ssl-endpoint#root-domain" rel="nofollow noreferrer">limitations</a> when using their SSL endpoint, I set up <a href="https://support.dnsimple.com/articles/domain-apex-heroku/" rel="nofollow noreferrer">DNSimple's Alias</a> to give me root URL functionality. </p>
  
  <p>Now I've got both the root and the www versions of the site up and running over SSL, but I'd like to redirect it all to www., which heroku suggests doing in the (Rails 3.2) app itself.</p>
  
  <p>These are some suggestions floating around for doing this:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/6701549/heroku-ssl-on-root-domain">add a before_filter in application_controller.rb</a> </li>
  <li><a href="https://www.bignerdranch.com/blog/redirect-www-subdomain-to-your-apex-domain-using-the-rails-router/" rel="nofollow noreferrer">redirect in the routes.rb file</a></li>
  <li>use a gem like this one: <a href="https://github.com/jtrupiano/rack-rewrite" rel="nofollow noreferrer">https://github.com/jtrupiano/rack-rewrite</a></li>
  </ul>
  
  <p>So what's the best/recommended way to redirect root URL's to www (incl https) in Rails? Details are appreciated since most examples show how to do it the other way around. </p>