I have looked all over the internet but could not get one final solution to what I would expect to be the 100% proper setup of DNS etc to get the following result on Heroku.com:
- Using a mydomain.com to show the content at myapp.herokuapp.com
- Redirecting all traffic from http://mydomain.com to http://www.mydomain.com (including subfolders)
I can get a bit of help from everywhere but nothing conclusive that will take care of the whole problem from DNS to rack-rewrite so that is why I am asking here (the support at my registrar and Heroku can only give me "their part").
What needs to be done is, as far as I understand:
Add mydomain.com and www.mydomain.com to Custom Domains at Heroku
Change CNAME to http://myapp.herokuapp.com in my registrars DNS. Question: Would it be both "www" and "*" that would use the CNAME redirection to myapp.herokuapp.com?
Add a "@" DNS record in order to handle naked domain requests (http://mydomain.com). Since this will not be done with CNAME, I am using the IP numbers at https://devcenter.heroku.com/articles/custom-domains, although they have severe uptime problems according to the article.
-- 1-3 leaves me with a website that will serve both http://mydomain.com and http://www.mydomain.com with the content at http://myapp.herokuapp.com
c. Now, I want to redirect everything from http://mydomain.com to http://www.mydomain.com and, according to Heroku support, this should be done with rack-rewrite (https://github.com/jtrupiano/rack-rewrite). Using the example in there, the code should then be:
r301 %r{.*}, 'http://mydomain.com$&', :if => Proc.new {|rack_env|
rack_env['SERVER_NAME'] != 'www.mydomain.com'
}
This, however, creates an eternal loop for me.
So, my question is now: What would be the proper workflow for Heroku and DNS-settings in order to achieve this setup?
It is very difficult to troubleshoot this, since trying out different DNS-settings by trial and error is very difficult (it's hard to know if they have gone through).