Main menu:


February 2014
M T W T F S S
« Jan   Mar »
 12
3456789
10111213141516
17181920212223
2425262728  

Archives

How to stop XML sitemap from appearing in Google search results

I use the All in One SEO Pack Plugin to generate my sitemap.xml file. For some reason, google decided to place the actual sitemap.xml in the search results instead of just the included urls.

After searching on google, I found suggestions to add the following to my .htaccess file.

<FilesMatch “sitemap.xml”>
Header set X-Robots-Tag “noindex”
</FilesMatch>

<Files sitemap.xml>
Header set X-Robots-Tag “noindex”
</Files>

Neither worked and I figured out that they wouldn’t since those are virtual files and the plugin generates them when the sitemap.xml is requested.
Instead, I opened wp-content/plugins/all-in-one-seo-pack/aioseop_sitemap.php and I looked for the following line:

echo ‘<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">’ . "\r\n";

I added the following line just after it then saved the file and uploaded it.

header("X-Robots-Tag: noindex", true);

This adds a x-robots-tag noindex http header to sitemap.xml requests and google doesn’t index the file. To verify, try opening your website.com/sitemap.xml through web-sniffer and look for the X-Robots-Tag:noindex http response header. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *