Home
Support Forums

Prevent Google from indexing default ___.netlify.app 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.
www CNAME example.netlify.app

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

I only want example.com indexed but not example.netlify.app.

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 example.netlify.app…

Add it only to the subdomain’s files.

Not sure if I get this right…

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

Now I can access the site with example.com but also still with the “old” subdomain example.netlify.app.
Since both serve the same files, how to just noindex example.netlify.app?

example.netlify.app and example.com 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 ___.netlify.app 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):

[[redirects]]
  from = "https://jonsully.netlify.app/*"
  to = "https://jonsully.net/:splat"
  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:


Jon

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”
:point_down:t2:
“Option 1: you can use _redirects to shove all traffic to your main domain”
:point_down:t2:
“Option 2: you can add your own canonical meta tags to your HTML”
:point_down:t2:
“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”

:+1:t2:

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.