146

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.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Andrew Latham
  • 5,982
  • 14
  • 47
  • 87
  • 8
    The Heroku FAQ only says how to do the redirect with DNSimple. Their support page links to StackOverflow. – Andrew Latham Jul 15 '12 at 14:14
  • 32
    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! :D – Daniel Morris Jul 05 '13 at 14:14
  • This should probably be closed as Dupe instead of Off-Topic: http://stackoverflow.com/questions/16022324/how-to-setup-dns-for-an-apex-domain-no-www-pointing-to-a-heroku-app – Chris Moschini Jul 11 '14 at 02:38
  • 2
    @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 Nov 20 '14 at 13:04
  • 1
    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 Feb 26 '16 at 06:44

5 Answers5

235

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.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Ryan Daigle
  • 11,599
  • 2
  • 36
  • 22
  • 14
    does this create a warning/error if your using SSL as heroku claims? they said if https:// example.com is redirected there is a warning. – Jaqx Jun 06 '13 at 07:04
  • 3
    @jaqx, this is happening to me, did you find a way to avoid users getting this warning? – jackerman09 Oct 25 '13 at 22:50
  • 3
    @jackerman09 I just got tired of the hassle and switched to DNSimple – Jaqx Oct 31 '13 at 08:18
  • This works, but the user ends up at www.example.com. I want them to end up at example.com. Is there a way to do this with godaddy? – Matt Dec 31 '13 at 03:02
  • 5
    @Matt there's no way to do this with GoDaddy. Use the ALIAS/ANAME feature of other providers like DNSimple or DNS Made Easy if you require this. – Ryan Daigle Dec 31 '13 at 15:28
  • 3
    @RyanDaigle Thanks Ryan. I recommend everyone leave godaddy for [more than one reason](http://www.authormedia.com/6-reasons-authors-should-avoid-godaddy/). [NameCheap.com](http://NameCheap.com) is who I use now. They are great, and they support what I was trying to do. Also, NameCheap accepts [bitcoin](https://www.namecheap.com/support/payment-options/bitcoin.aspx). – Matt Jan 01 '14 at 19:13
  • The A record has changed: `For your domain name to forward, its A record must be pointed to 50.63.202.1` (from the same link as in the answer) – Alex Reinking Sep 20 '14 at 21:13
  • CloudFlare will be the best solution, CloudFlare support "CNAME Flattening" FOR FREE, so you can create a CNAME record that sets root/apex/naked domain to yourapp.herokuapp.com. – Howard Feb 06 '15 at 14:22
22

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.

TMilligan
  • 3,520
  • 1
  • 18
  • 12
  • 5
    why pay another fee to someone else? – Benjamin Mar 25 '13 at 08:55
  • 4
    You, sir, are a lifesaver. @Vezu: non-ssl forwarding is completely free. You just point your A record for the naked domain to that IP address and it will redirect the browser to the www domain. You don't even need an account with them. – P O'Conbhui May 04 '13 at 00:48
  • I'm trying to incorporate wwwizer for mine, and in my A record I have the host as "@" and the points to as 174.129.25.170, per wwwizer's instructions, but I get their error message page when I visit my naked domain! Did I do this correctly?? – tx291 Feb 27 '17 at 17:10
8

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.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
kobaltz
  • 6,980
  • 1
  • 35
  • 52
  • 1
    Would the IP address and web address for Heroku be appname.heroku.com or proxy.heroku.com? – Andrew Latham Jul 15 '12 at 14:42
  • 1
    You should really look at this article, https://devcenter.heroku.com/articles/custom-domains, as it covers everything that you're looking to do. – kobaltz Jul 15 '12 at 14:44
  • 1
    This approach points the CNAME `www` to @ which still routes traffic through to fixed IP addresses (which has all the same downsides as A-records). Use a top-level redirect, on GoDaddy this is called "forwarding", instead. – Ryan Daigle Jul 15 '12 at 17:41
5

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.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
John Beynon
  • 37,398
  • 8
  • 88
  • 97
3

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
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
blnc
  • 4,384
  • 1
  • 28
  • 42