SEO Tip - Prevent Search Engines from Indexing your XML Sitemaps

Published in: SEO - sitemaps

XML Sitemaps are plain text files that help you inform Google about every single web page, image and video file that is available on your site. For instance, if there’s a page on your site that may be hard to discover because none of the other pages /sites are linking to it, Google can possibly reach it through the Sitemaps file.

Sitemaps are created primarily for search engines but since they also have text, they may even show-up in regular search results thus competing with your other web pages. To see this for yourself, try a search query like filetype:xml inurl:sitemap on Google.

You can easily prevent HTML based web pages from getting indexed through the use of META tags but such a feature is not available for XML based Sitemaps.

Prevent your Site’s XML Sitemaps from showing up in Google Search Results

Prevent Google from Indexing your XML Sitemaps

John Mueller of Google, in a tweet, suggested an alternate solution – serve sitemap files with a “noindex x-robots-tag” to prevent them from getting indexed.

It should take no more than a minute to implement John’s suggestion. Here’s how:

Switch to the directory on your Apache web server where the sitemap files are (they are generally located in the top-level folder of the blog) and open the .htaccess file for editing.

If you have only one XML Sitemap file, add this code to your .htaccess file.

 <IfModule mod_rewrite.c>
  <Files sitemap.xml>
   Header set X-Robots-Tag "noindex"

Do replace the word “sitemap.xml” in the code with the actual name of your Sitemap file.

If you have more than one sitemap (like for imagesvideos or in the case of Blogger blogs that support multiple sitemaps), use the following code instead. Remember to replace sitemap1, sitemap2, etc. with the actual file names.

 <IfModule mod_rewrite.c>
  <Files ~ "^(sitemap1|sitemap2|sitemap3)\\.xml$">
   Header set X-Robots-Tag "noindex"

Test your .htaccess changes

Once you have saved the changes in your .htaccess file, go to URI Valet and copy-paste the full URL of any of your XML Sitemaps.

If you have the X-Robots Tag with noindex listed in the Server Response, the implementation was successful and your sitemaps should no longer make an appearance in Google and other search engines.

Also see: Google Experts Answer your SEO Questions

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: SEO - sitemaps

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube