Score:1

Apache LocationMatch match group and use in a header

eg flag
egt

I am trying to get a pattern from an URL, and to use it in a header.

Something like

<LocationMatch "^/static/(?<sitename>[^/]+)">
 Header set Content-Security-Policy-Report-Only "frame-ancestors 'none'; report-uri https://csp-reporter.com/%{env:MATCH_SITENAME}"
</LocationMatch>

As documented here

I am getting an error

AH00526: Syntax error on line XXX of XXX/httpd.conf:
Unrecognized header format %

We are using Apache 2.4.46

Any idea what is wrong?

Score:0
cc flag

if I remember correctly, I had a similar error and it was because I had forgotten the always... Header always set Content-Security-Policy-Report-Only "frame-ancestors...

egt avatar
eg flag
egt
Thanks for you response! I should have mentionned, it works fine if I remove `%{env:MATCH_SITENAME}`
lejurassien avatar
cc flag
you are using apache version 2.4.46 and the directive is for apache 2.4.8 min wouldn't be the problem? From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" it'is in your link [link]https://httpd.apache.org/docs/2.4/mod/core.html#locationmatch[/link]
egt avatar
eg flag
egt
Isn't 2.4.46 > 2.4.8? Latest is 2.4.48 https://httpd.apache.org/download.cgi
lejurassien avatar
cc flag
nop 2.4.46<2.4.48 right?
egt avatar
eg flag
egt
The documentation states `From 2.4.8 onwards`, so I expect it to work with 2.4.46
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.