How to Prevent Netlify Subdomain from Being Indexed ?

I'm hosting a site on Netlify and using a custom domain (e.g., mydomain.com). I want to make sure the custom domain gets indexed by search engines, but I need to prevent the Netlify subdomain (myproject.netlify.app) from being indexed. Does anyone know how to handle this properly, especially if I'll be moving to Astro later? Are there any built-in Netlify features or other suggestions for this scenario?
5 Replies
b1mind
b1mind3mo ago
Are you using Netlify DNS/Nameservers? FAIK if you are using them to serv it shouldn't effect it.
b1mind
b1mind3mo ago
Redirects and rewrites
Manage traffic to your site by defining redirect or rewrite rules in a _redirects file or a netlify.toml file.
b1mind
b1mind3mo ago
you can also setup a _redirect though
Pixel Mamelon
Pixel MamelonOP3mo ago
I haven’t started using them yet (but I will) .Instead, I added an A record and CNAME to the client’s domain registrar because I didn’t want to risk touching any email-related records at this point. Adding the A record was a bad idea (for anyone reading this, it's better to use an ALIAS instead, if possible). While the solution you shared (redirects) is great, I was hoping to avoid losing myproject.netlify.app. I actually found it pretty helpful when the main site was down. Maybe I’ll try to figure out Netlify previews instead if nothing else works ,and let it go. Another possible solution I found, suggested by ChatGPT, is to add a conditional meta tag using a script (Netlify snippet injection). Since the current version of the site is built with plain HTML while the rest of the site is still being developed, this approach would theoretically work. But I’m wondering if anyone is familiar with something like this as I don't see it in documentation.. <script> if (window.location.hostname === 'domain.netlify.app') { const meta = document.createElement('meta'); meta.name = "robots"; meta.content = "noindex"; document.head.appendChild(meta); } </script> Thank you for the share!
Jake
Jake3mo ago
As an SEO, I can confirm that adding a noindex tag is the preferred approach here
Want results from more Discord servers?
Add your server