146
votes

I am trying to figure out how to get the naked domain for my website to redirect to the www domain. I am using Heroku and have the domain from GoDaddy. Because of Heroku, my A records are already set up as:

@: 75.101.145.87

@: 75.101.163.44

@: 174.129.25.170

And my www CNAME points to proxy.heroku.com.

I've been looking all over the internet, but can't find a simple, free answer for how I can do this redirect. Some answers discuss using paid services, which I don't want to do, and others talk about going in and modifying Heroku settings, but then don't really give much explanation. Right now, if you go to my naked domain, it's just Heroku saying that no such app exists, while if you go to my www domain it's my app.

5
The Heroku FAQ only says how to do the redirect with DNSimple. Their support page links to StackOverflow.Andrew Latham
I think Emil's response is a bit harsh on this, this site is a resource for solving problems we have along the journey of programming and that is a problem i'm having right now! :DDaniel Morris
This should probably be closed as Dupe instead of Off-Topic: stackoverflow.com/questions/16022324/…Chris Moschini
@ChrisMoschini the accepted answer at the question you reference does not work on GoDaddy because GoDaddy doesn't support ALIAS records, only CNAME. This is its own question I think.Topher Hunt
Whatever A Records is set there is no possibility to have a naked domain pointed directly to heroku. We could only set it to be routed to www which CNAME is pointed to your-app-name.herokuapp.com.eQ19

5 Answers

233
votes

On GoDaddy, use the "Forwarding" feature to setup a forward from yourdomain.example to www.yourdomain.example. The forwarding feature can be accessed in the Domain Manager at the bottom of the "Domain Information" section:

Domain forwarding in GoDaddy

If you do this then all traffic to yourdomain.example will be routed to the Heroku app CNAME (which is the better approach).

One note, however, if you are on the Cedar stack then don't use proxy.heroku.com for the host of your www CNAME. Instead use your-app-name.herokuapp.com. These details are covered here.

GoDaddy also specifies that in order for your domain name to forward, its A record must be pointed to 64.202.189.170 or must fall between the following ranges: 50.63.202.1 - 50.63.202.31 or 184.168.221.1 - 184.168.221.31.

22
votes

You could also use http://wwwizer.com to forward from your naked domain to your www. In GoDaddy in the DNS manager under the A record in the @ heading type in 174.129.25.170. They will automatically redirect from the naked domain to one with www. in front of it.

8
votes

In GoDaddy's DNS Zone Editor, you will want to configure your CNAME record www to point to @. In your A Record, you'll use a wildcard (*) to point to the IP address and a second A Record that uses @ as the host that will also point to the web address. This way,

subdomain1.example.com will forward to your IP
www.example.com will forward to your IP
silly.example.com will forward to your IP
anything.example.com will forward to your IP

Frequently Asked Questions

Can I point *.mydomain.example to my Heroku app?

Yes, using the free Custom Domains feature of Heroku you can point a wildcard domain to your application.

What IP addresses should I use to point my custom domain to Heroku?

The Heroku routing stack uses a collection of IP addresses that can change at any time, and using A records to point to your app is not supported. To ensure your domain always points correctly to the routing mesh, configure subdomains (e.g. www in www.example.org) using a CNAME record:

If the app is on…   Then CNAME the subdomain to
Bamboo  yourapp.heroku.com
Cedar   yourapp.herokuapp.com

Naked (or bare/apex) domains (e.g. example.org) should be avoided because of their availability and uptime consequences.

Why can't I add subdomain.mydomain.example for my app?

In some cases, attempts to add a custom domain (like subdomain.mydomain.example) for an app may result in an error like this:

 ! mydomain.example is owned by another user

All applications for a given base domain must be owned by the same Heroku account. The above error means that someone else has already added a mydomain.example custom domain to one of their apps.

5
votes

If you have the IP addresses setup on your naked domain and your www cname'd to yourappname.herokuapp.com then all you need do is use something like RackRewrite in your application to redirect the requests when they arrive at your application.

What you want to setup is any request to the naked domain gets redirected to your www address. After following the installation instructions add an initializer in config/initializers

 ApplicationName::Application.config.middleware.insert_before(Rack::Lock, Rack
 r301 %r{.*}, 'http://www.yourdomain.example$&', :if => Proc.new {|rack_env
  rack_env['SERVER_NAME'] != 'www.yourdomain.example'
 }
 end if Rails.env == 'production'

Which is saying, if the requested URL is not www.yourdomain.example then 301 redirect it to the www.yuordomain.example but only if it's running in production.

3
votes

For this to work with Network Solutions do the following:

Network Solutions pointing yourdomain.example to www.yourdomain.example. Here's how.

  1. Within Account Manager, select My Domain Names

  2. Select the domain name that you want to manage

  3. In the green box, select Change Where Domain Points

  4. Select Advanced DNS, then Continue

  5. First, edit the A Records by selecting Edit A Records

    *For the "@ none" enter the following IP address 205.178.189.129, clear the records for the "www" and " (All others)"**, then select Continue

  6. Second, edit the Host Aliases (CNAME records) by selecting Edit CNAME Records

    Enter "www" in the Alias column

    Leave TTL set to 7200 but on the same line, enter the name servers provided by the blogging service in the Other Host section [ IE FOLLOW THE HEROKU INSTRUCTIONS NOW www --> yourapp.herokuapp.com (Cedar Stack) ]

    Select Continue

Now wait and check the domain(s) with the following terminal command:

host domain.example
host www.domain.example