Why does a custom domain redirect to herokuapp.com?

Viewed 4311

According to this Heroku documentation we can allow a Heroku app hosted at myapp.herokuapp.com to be accessed with a custom domain myapp.com.

I have added the follow records to my GoDaddy DNS Zone File:

A (Host)
Host        Points To                    TTL
--------------------------------------------------
@           50.63.202.1                  1/2 Hour


CName (Alias)
Host        Points To                    TTL
--------------------------------------------------
email       email.secureserver.net       1/2 Hour
ftp         @                            1/2 Hour
www         myapp.herokuapp.com          1/2 Hour

Normally the A record points to a server. In this case Heroku doesn't provide an IP address for its cloud applications, and apparently CNAME is enough.

Navigating to www.myapp.com or myapp.com redirects to https://myapp.herokuapp.com. However, navigating to http://www.myapp.com/blog/post/1 (any address not the homepage) will stay with the www.myapp.com domain, and clicking links is OK -- Except when clicking a link to the homepage we are redirected to the myapp.herokuapp.com address.

How can it be set up so the visitor does not see the herokuapp.com address unless visiting it with that address?

The output of heroku logs --tail --app myapp:

2016-03-11T01:13:49.756887+00:00 heroku[router]: at=info method=GET path="/" host=vast-hamlet-33090.herokuapp.com request_id=6177aa6c-dc5f-4de5-a1c6-1ff8b1194849 fwd="24.17.117.236" dyno=web.1 connect=1ms service=24ms status=304 bytes=181
2016-03-11T01:13:49.760014+00:00 app[web.1]: 24.17.117.236 - - [11/Mar/2016:01:13:49 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"

It looks like the app never receives a request from www.myapp.com, but only myapp.herokuapp.com.

The output of heroku domains -a myapp:

=== myapp Heroku Domain
myapp.herokuapp.com

=== myapp Custom Domains
Domain Name         DNS Target
------------------  -------------------
www.myapp.com       myapp.herokuapp.com
myapp.com           myapp.herokuapp.com
3 Answers

For newer version of Ghost (3.x) while using the https://github.com/SNathJr/ghost-on-heroku deploy script, I updated the APP_PUBLIC_URL to use http://example.com.

Also I set a page rule in Cloudflare to use http://*example.com/* with the setting: Always use HTTPS

To follow up in a later date. I had the same issue. Using Heroku + Cloudflare + Custom domain. Andrei Erdoss answer works.

https in APP_PUBLIC_URL will cause 301 redirects.


For newer version of Ghost (3.x) while using the https://github.com/SNathJr/ghost-on-heroku deploy script, I updated the APP_PUBLIC_URL to use http://example.com.

Also I set a page rule in Cloudflare to use http://example.com/ with the setting: Always use HTTPS


Related