I want to set different HTTP header depending on the URL. In my particular case I want a specific URL (e.g. regex ^/abc$
) to have a different header than all the rest.
I am trying this:
<IfModule mod_headers.c>
<If "%{REQUEST_URI} =~ /^/abc$/">
Header set Content-Security-Policy: "default-src 'none'; style-src 'self' 'unsafe-inline';"
</If>
<Else>
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';"
</Else>
</IfModule>
However this doesn't seem to work, the log says:
Cannot parse condition clause: Failed to compile regular expression
What am I doing wrong and how can I make this to work?
I also tried the alternate regex form m#^/abc$#
and then there is no error but there is no match for the If condition.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…