Our default expected behavior to almost all apps is that the naked domain (like mydomain.com
) get redirected to our real app at a subdomain (common to be www.mydomain.com
).
We use this as our default and main solution, since Heroku says that it does not support naked domains (like mydomain.com
) using DNS A-records. Heroku have a document explaining it's decision and limitations to this model.
You should configure canonical host and Heroku custom domains doing:
$ heroku config:add CANONICAL_HOST=www.mydomain.com
$ heroku domains:add mydomain.com
$ heroku domains:add www.mydomain.com
This way rack-canonical-host middleware will redirect all requests to your app to the correct domain (www.mydomain.com
) if the request comes from any other domain, like mydomain.com
or mydomain.herokuapp.com
. This is necessary because your app should only be acessible from one domain. This prevents SEO concerns, security issues and is more consistent.
Godaddy and registro.br doen't support alias
or aname
configuration for domains with Heroku. If you insist to use these services the app will not respond to domains without www.
If you use Zerigo DNS Add-on you need configure nothing more. The redirects from naked domain to the canonical host will just happens.
Modern DNS servers like DNS simple and DNS made easy support CNAME-like functionality at naked domain level. It's called ALIAS
at DNSimple and ANAME
at DNS Made Easy.
On this kind of DNS servers you should configure like if you was configuring a regular CNAME.
ALIAS mydomain.com mydomain.herokuapp.com.
CNAME www.mydomain.com mydomain.herokuapp.com.
With this completed, we have the following results:
myapp.herokuapp.com redirects to www.myapp.com
myapp.com redirects to www.myapp.com
www.myapp.com answers the request
So our content is available in just one url while others give the redirect.