I assume this is not really a difficult issue but I am using so many different solutions and don’t really know what it best.
I am using Ruby on Rails and have my apps on Heroku and I want to 301 redirect everything on my naked domain (@) to my www-domain. E.g.
http://domain.com –> http://www.domain.com
http://domain.com/subpage –> http://www.domain.com/subpage
Right now I am handling this with my DNS by first deleting both @ and www entries. Then I set a redirect of the entire website to http://www.domain.com (which re-creates the DNS entries for both @ and www). Lastly I change my www DNS-entry to CNAME and the name of the heroku-app (http://myapp.herokuapp.com).
This seems to be forwarding http://domain.com/subpage to http://www.domain.com (without the subpage).
What I am looking for now is the proper/recommended way to handle this in a simple/elegant way.
DNS?
Routes?
.htaccess? (if so, how do I alter .htaccess in RubyOnRails)
Thanks in advance!
In the end what I had to do was to point the @-DNS to my normal web host (since @ demands an IP and Heroku will only accept CNAME) and the www-DNS to Heroku.
At my normal webhost I put a .htaccess that redirected all traffic there to my www-domain like this: