SEO Tip - Prevent Search Engines from Indexing your XML 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"
  </Files>
 </IfModule>

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"
  </Files>
 </IfModule>

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

Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

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.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

0

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.