Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a custom domain redirect to herokuapp.com?

Tags:

heroku

ghost

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
like image 759
Michael Fulton Avatar asked Mar 09 '16 05:03

Michael Fulton


People also ask

Does Heroku support custom domain?

You can buy a custom domain name with a domain registration service. Add the custom domain to your app with the heroku domains:add command. Look up the Heroku-supplied DNS target for the custom domain using the heroku domains command. Configure your app's DNS provider to point to the Heroku-supplied DNS target.

Why does my domain redirect?

Your website is redirecting to another website because it has been infected with malware. Typically this happens when a malicious individual gains access to your website through a vulnerable plugin or theme.

How do I stop domain redirection?

To Disable an Addon Domain Redirect In the “DOMAINS” section, click the “Addon Domains” link or icon. Click the “Manage Redirection” link corresponding to the Addon domain you wish to manage. In the “Disable Addon Domain Redirection” section, click the “Disable Redirection” button.


Video Answer


2 Answers

In my case using Ghost, updating the HEROKU_URL in the Ghost configuration to 'http://www.myapp.com' fixed this error. I thought I had this set up, but I changed it to 'http://myapp.herokuapp.com' so I could access the admin panel, which wasn't accepting requests from URLs not HEROKU_URL.

I was also having a separate issue with Chrome automatically, helpfully-not-helpfully redirecting before the request hit the server, so the Node app received a request for myapp.herokuapp.com. I discovered this by trying to use another browser to access my app. I cleared the browser cookies and cache and myapp.com was no longer redirected in Chrome.

like image 183
Michael Fulton Avatar answered Oct 05 '22 16:10

Michael Fulton


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

like image 34
Andrei Erdoss Avatar answered Oct 05 '22 14:10

Andrei Erdoss