Good SEO practice of netlify deployment url and custom domain

I deploy my website to netlify, and now basically my netlify subdomain and my custom domain are duplicates. It is not desired for the sake of SEO.
I googled to get an easy way that is to add rel=“canonical” in the header. How should I do it correctly, should I point every netlify page to my custom page url?
If so, how should I get the real url that user is visiting? Is it possible in Hugo?
Or do you have better solutions?
Thanks, guys.

Your Netlify subdomain should not be visible to Google. It can index only what it can see. But you could set it up in Google Webmaster tools (verify via html-file) and then maybe disavow all pages in that Netlify subdomain?

But to be honest, that would be a perfect question to the Netlify support.

The canonical meta-tag is more for things inside of a domain like and is the same content (for instance single pages inside of tags)

Hugo can generate robots.txt for you. Allow or disallow according to the environnement (Netlify or other) this is how I did it for this project:

You must enable robots txt generating in your configuration file. Checkout the doc.

Hello regis,
Thanks a lot. It is exactly what I am looking for.
But could you please shed more light on it? Both custom and netlify subdomain points to the same files.
Your method basically generates two robots.txt files for both of them, right?
Then it could automatically switch between these two robots.txt files based on the traffic entry?

I will do the test by myself, and I want to know how it exactly works.

Mmm I didn’t get that. Then you should look for htaccess i think it can catch the domain then you’ll have to make it block robots.

But @davidsneighbour is right, google search console should definitely slove your problem.

Hello @davidsneighbour, thanks. I will try it now.

To anybody who still concerns, this is the solution replied form Netlify.

If you aren’t sharing the Netlify URL’s then I don’t think it would actually cause a problem. However if you are concerned, you can add a _redirects file to your publish directory with the following contents:* 301!* 301!
That will redirect requests that are made to your netlify subdomain to your custom domain. You can read more about redirects at (