title: Set Header using REQUEST_URI and ap_expr in Apache 2.4
body: <p>I need to set a noindex header for our sitemap.xml page. I can't use a <code>&lt;meta&gt;</code> tag, so the other option seems to involve setting a header via Apache. </p>
  
  <p>Additionally, I can't use the <code>&lt;Files&gt;</code> directive because our sitemap.xml is generated by PHP and is not a file.</p>
  
  <p>I've tried this, but I don't think <code>RewriteCond</code> works in conjunction with <code>Header</code> because this is affecting all pages:</p>
  
  <pre><code>RewriteCond %{REQUEST_URI} ^/sitemap\.xml$ [NC]
  Header set X-Robots-Tag "noindex"
  </code></pre>
  
  <p>This doesn't produce any effect:</p>
  
  <pre><code>&lt;If "%{REQUEST_URI} =~ /^sitemap.xml$/"&gt;
      Header set X-Robots-Tag "noindex"
  &lt;/If&gt;
  </code></pre>
  
  <p>It seems like the best option would be to use <a href="https://httpd.apache.org/docs/trunk/expr.html" rel="nofollow noreferrer">ap_expr</a>, but this doesn't work either:</p>
  
  <pre><code>Header set X-Robots-Tag "noindex" "expr=%{REQUEST_URI} =~ m#^/sitemap\.xml$#i"
  </code></pre>
  
  <p>Can someone spot a regex problem? Am I misunderstanding how one or more of these techniques should be used?</p>
  
  <p>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.</p>