Sitemap is an important part of your site that contains the information of every single page, videos, images to notify Google. For instance, sitemap plays a great roll to help Google to discover a page you have in your website that is not linked through other post/pages.
The problem is that, as it contains a lot of text, it can stay at a higher position in the search results, competing with other post or pages. So it is better to prevent search engines from indexing your sitemap files. But, if it would be a normal HTML page then you could easily do that by adding a Noindex meta tag. Unfortunately, XML file does not allow you to do so. Here is the simple solution.
Download your site’s .htaccess file residing at the root folder of your site. Open it with any text editor and then just add this code in your .htaccess file.
<IfModule mod_rewrite.c> <Files sitemap.xml> Header set X-Robots-Tag "noindex" </Files> </IfModule>
If you have multiple XML sitemap files in your site then you should put the code as following:
<IfModule mod_rewrite.c> <Files ~ "^(sitemap1|sitemap2|sitemap3).xml$"> Header set X-Robots-Tag "noindex" </Files> </IfModule>
Save the changes and upload the file to its original location, replacing the older one.
How can I check that the code worked properly?
Well, go to URI Valet and put the full path of your sitemap.xml file.
If you notice the entry X-Robots-Tag with noindex in the server response, your implementation is successful.
[Via Digital Inspiration] .