cant point Hostinger custom domain to herokuapp

Viewed 2776

I have deployed a django based app on heroku which works (https://vikastiwari.herokuapp.com)

I have a domain that i bought from hostinger (vikastiwari.space)

Now i want to use my hostinger domain with herokuapp and I followed the process mentioned at heroku that I should point my DNS CNAME to server returned by heroku. So I added cname records but it is still not working.

Please tell me how can I point my domain to this free herokuapp

2 Answers

I've tried this tutorial:

https://www.mirrorcommunications.com/blog/how-to-correctly-point-your-domain-to-heroku

If you found another solution, could you put here?

I've created in Heroku two custom domains:

One with www www.namesite.com and another without www namesite.com.

After this, in Hostinger > Domain > DNS ZONE I changed in CNAME table the values Point to from the hosts @ and www with the DNS heroku's 'DNS target' of two created domains.

The A DNS Record requires an IP Address.

This represents your domain without 'www.' i.e. https://example.com

Heroku cannot provide an IP Address since it constantly changes. They provide urls.

Which is perfect for CNAME Records.

CNAME represents your domain with the www. 'prefix'. i.e. 'https://www.example.com'

But it is an issue for A Records since an IP Address is required.

Meaning if you add the CNAME Record, 'https://www.example.com' will redirect to your Heroku app, but 'https://example.com' will not.


Newer services support CNAME flattening/ALIAS/ANAME.

CNAME flattening/ALIAS/ANAME is the equivalent of being able to add a URL to am A Record instead of an IP Address.

This fixes the issue since you can simply add your Heroku URL.

Hostinger, however, does not support CNAME flattening/ALIAS/ANAME yet.


Another solution is to use DNS Forwarding, but that is also not available on Hostinger unless you move to Clouflare


Hostinger has a "Redirect" section in cPanel but that didn’t work in redirecting 'https://example.com' to 'https://www.example.com' either.


A workaround for all these issues on Hostinger is to add an A Record in DNS Management that points to your Hostinger server IP Address.

In that server we create an .htcaccess file.

And in that file we add code for a permanent 301 redirect to your 'https://www.example.com' (i.e. your Heroku app).

Below is the code that should be added to your .htcaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

The way to get the IP Address of Hostinger to point to that .htcaccess file is by checking the left panel inside the cPanel or going into Details section.


You can show this to your Hostinger support in the chat section and they can do it for you.

Related