title: How to set Apache conditional header based on URL?
body: <p>I want to set different HTTP header depending on the URL. In my particular case I want a specific URL (e.g. regex <code>^/abc$</code>) to have a different header than all the rest.</p>
  
  <p>I am trying this:</p>
  
  <pre><code>&lt;IfModule mod_headers.c&gt;
      &lt;If "%{REQUEST_URI} =~ /^\/abc$/"&gt;
          Header set Content-Security-Policy: "default-src 'none'; style-src 'self' 'unsafe-inline';"
      &lt;/If&gt;
      &lt;Else&gt;
          Header set Content-Security-Policy: "default-src 'none'; child-src https: *.youtube.com 'self'; connect-src 'self'; font-src 'self'; img-src 'self'; script-src https: *.ytimg.com *.youtube.com 'self'; style-src 'self';"
      &lt;/Else&gt;
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>However this doesn't seem to work, the log says:</p>
  
  <pre><code>Cannot parse condition clause: Failed to compile regular expression
  </code></pre>
  
  <p>What am I doing wrong and how can I make this to work?</p>
  
  <p>I also tried the alternate regex form <code>m#^/abc$#</code> and then there is no error but there is no match for the If condition.</p>