For Heroku to receive traffic at the apex domain (your-tld.com
) Your DNS provider must support ANAME / ALIAS resolution for a hostname (your-app-random-heroku-endpoint.herokudns.com
) to the apex domain.
GoDaddy does not support this, you can only set up an A record to a static IP address for the apex.
They provide domain forwarding, but this does not work for HTTPS, so requests to https://your-tld.com will timeout. Their domain forwarding service will only work for forwarding from http://your-tld.com.
If you're using GoDaddy, it is recommended to transfer or switch name servers to a different service (e.g. Namecheap, DNSimple, etc).
The simplest way to support the combination of http/https/apex redirection to https://www.your-tld.com is with route matching.
# routes.rb
YourApp::Application.routes.draw
constraints subdomain: "" do
match "(*any)" => redirect { |params, request| URI.parse(request.url).tap { |uri| uri.host = uri.host.prepend("www.") }.to_s }
end
# ...
Handling this with rack middleware is more performant, but tricky to get right with SSL. Unless you are expecting massive redirection traffic, this is not recommended.