Linked Questions

Popular Questions

I need to set a noindex header for our sitemap.xml page. I can't use a <meta> tag, so the other option seems to involve setting a header via Apache.

Additionally, I can't use the <Files> directive because our sitemap.xml is generated by PHP and is not a file.

I've tried this, but I don't think RewriteCond works in conjunction with Header because this is affecting all pages:

RewriteCond %{REQUEST_URI} ^/sitemap\.xml$ [NC]
Header set X-Robots-Tag "noindex"

This doesn't produce any effect:

<If "%{REQUEST_URI} =~ /^sitemap.xml$/">
    Header set X-Robots-Tag "noindex"

It seems like the best option would be to use ap_expr, but this doesn't work either:

Header set X-Robots-Tag "noindex" "expr=%{REQUEST_URI} =~ m#^/sitemap\.xml$#i"

Can someone spot a regex problem? Am I misunderstanding how one or more of these techniques should be used?

For what it's worth, we prefer to version control our .htaccess files and therefore don't put config items like these in httpd.conf or vhost etc.

Related Questions