If you have a website hosted on Netlify, you may want to disable search engine indexing for various reasons. For example, if you are starting to design your website, you may not want Google to index your unfinished website.
There are 3 ways to disable search engine indexing for a Netlify site. Let’s discuss them one by one.
- Using meta tags
- Using robots.txt
- Using headers.
If you are wondering which method to use, don’t worry since we will discuss the pros and cons of these methods.
1. Using meta tags
Meta tags are HTML tags that provide information about the content of a web page. You can use meta tags to disable search engine indexing for your website.
To disable search engine indexing for a webpage, you can add the noindex
meta tag to the head section of your website.
To prevent all search engines from indexing your website, you can add the following meta tag to the head section of your website.
<meta name="robots" content="noindex">
To prevent only Google from indexing your website, you can add the following meta tag to the head section of your website.
<meta name="googlebot" content="noindex">
Pros
- You can disable search engine indexing for a specific page.
- You can disable search engine indexing for specific crawlers.
Cons
- You have to add the meta tag to every page of your website that you don’t want to be indexed.
- It blocks only HTML resources from being indexed. It doesn’t block indexing of images, other media files and static assets.
2. Using robots.txt
You can use robots.txt to disable search engine indexing for your website. To disable search engine indexing for your website, you can add the following to the robots.txt file.
# Example 1: Block only Googlebot
User-agent: Googlebot
Disallow: /
# Example 2: Block Googlebot and Adsbot
User-agent: Googlebot
User-agent: AdsBot-Google
Disallow: /
# Example 3: Block all crawlers except AdsBot (AdsBot crawlers must be named explicitly)
User-agent: *
Disallow: /
Pros
- You can disable search engine indexing for all pages of your website.
- You can disable search engine indexing for images, other media files and static assets.
- You can disable search engine indexing for specific crawlers.
Cons
- A page that’s disallowed in robots.txt can still be indexed if linked to from other sites.
3. Using headers
You can use HTTP headers to disable search engine indexing for your website. For this you have to use X-Robots-Tag = "noindex"
header.
In order to tell Netlify to add the header to all (or some) page(s) of your website, you have to create a file named netlify.toml
in the root directory of your website.
Then, you have to specify the url pattern for which you want to add the header. For example, if you want to add the header to all pages of your website, you can use /*
as the url pattern.
# netlify.toml
[[headers]]
for = "/*" # This header will be applied to all pages
[headers.values]
X-Robots-Tag = "noindex, nofollow, noarchive, nosnippet" # The 'noindex' value disables search engine indexing
Pros
- You can disable search engine indexing for all pages of your website.
- You can disable search engine indexing for images, other media files and static assets.
Cons
- You can’t disable search engine indexing for specific crawlers.
Which method to use?
Using headers to disable search engine indexing seems to be the best method. You can disable search engine indexing for all pages of your website and also for images, other media files and static assets. You can also disable search engine indexing for all crawlers. This is also the easiest method since you don’t have to add any code to your website. It is also a flexible method since you can use wildcards to specify the url pattern for which you want to add the header.
However, if you want to disable search engine indexing for specific crawlers, you can’t use headers. In that case, you can use meta tags or robots.txt.
Tools to check if search engine indexing is disabled
Following are some useful tools that you can use to check if search engine indexing is disabled for your website.
Conclusion
In this article, we discussed 3 ways to disable search engine indexing for your Netlify website. We also discussed the pros and cons of each method.