Prevent Google from indexing default domain when using a custom domain

Hi Guys and Girls

I’ve launched a new website. Now I added the CNAME records to my hosting provider.

Now my question is, Does google index, when the APEX domain is and will be in sync I guess?

I only want indexed but not

Anything I must do?

Add this to all your pages’ <head>: <meta name = "robots" content = "noindex">.

But i want the site indexed, just not the…

Add it only to the subdomain’s files.

Not sure if I get this right…

I’ve developed on, now I’ve set up the custom domain (from the hoster I point to netlify with CNAMEs), and can reach the site with

Now I can access the site with but also still with the “old” subdomain
Since both serve the same files, how to just noindex and is the same site.

Now I get it. Well, then I guess you’d have to try using headers. You’d have to add a header to your subdomain. Something like this in your _headers file:

  X-Robots-Tag: noindex

Hey @MarcFuSa

Let me short circuit the conversation here — Netlify will automatically send back a canonical Link header for any site that is using a custom domain but which receives a request at their automatically-assigned domain. You don’t need to do anything on your end.

If you want even more redirection, you can setup a custom redirect that would look like (toml format):

  from = "*"
  to = ""
  force = true

To force all traffic to your primary domain in the first place. This is what I do for my site (example above is live), but it’s unnecessary and does not impact SEO one way or another thanks to Netlify automatic Link header.

Hope that helps :slight_smile:


P.S. I adjusted this post’s title to better fit / clarify the use-case for future searchers :netliheart:

HI @ jonsully

Thats nice I don’t have to worry about that :slightly_smiling_face:
So I don’t even have to set canonical’s, since netlify does it?

Im asking because the post you linked, he says you do either redirect OR canonical.

I think that may just be a writing style thing. I believe David wrote with the intention of:

“When you add a custom domain, you’re serving the same content on two domains - bad for SEO”
“Option 1: you can use _redirects to shove all traffic to your main domain”
“Option 2: you can add your own canonical meta tags to your HTML”
“Since option 2 is better but we don’t want to force everyone to have to wire up canonical tags, we’re going to automatically do this for you as a Link header”


Does sending back a canonical link also work if I use a Cloudflare DNS instead of the Netlify one.

Hi @StefanBratanov,

I’m not sure how canonical links are related to Cloudflare DNS. It would work the same regardless of what DNS is being used.


Sorry for interjecting into the discussion. Can u please let me know how can I add this into my Hugo site?

Based on the discussion above, by the presence of the canonical tags, you don’t need to add any no index tags. Are you looking for something specific?