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] .
Aha, great tutorial mate. I think it is quite a nice idea to hide the sitemap from search engines since I think it is better it does not show to the readers
Absolutely Shiva. Thanks for your comment.
X-Robots tags is used only in Apache Hosted sites not for IIS Hosted sites because IIS Not support .htaccess. Reply mee
Yes….This method is only for the Apache servers. The article is based on the WordPress blogs. BTW thanks for your comment.
my server is Window and its not support .htaccess file than how i can do it in web.config file ?
pls if u have any idea let me know.
Thanks
vijay lathiya