Apache header 上的正则表达式搜索和替换编辑

Regex search and replace on Apache header edit

我在 .htaccess 文件中有下一个代码

<IfModule mod_headers.c>
        Header set Content-Security-Policy "base-uri http://site.local/"
        Header append Content-Security-Policy "default-src 'none'"
        Header append Content-Security-Policy "connect-src 'self'"
        Header append Content-Security-Policy "style-src 'self'"
        Header edit Content-Security-Policy "," ";"
</IfModule>

从服务器生成下一个响应 header:

Content-Security-Policy base-uri http://site.local/, default-src 'none', connect-src 'self', style-src 'self'

我想用分号而不是逗号获取该行,如下所示:

Content-Security-Policy base-uri http://site.local/; default-src 'none'; connect-src 'self'; style-src 'self'

Using append or merge on Apache's mod_headers separates the different additions to the header previously set with a comma, as the standard seems to point, but the W3C dictates that the different configurations of the Content Security Policy have to be separated with a semicolon.

我找不到编写 Header 编辑行以将“,”替换为“;”的方法根据 W3C 状态。

我尝试了很多搜索变体,我知道有些是错误的,但由于我没有得到预期的结果,所以我正在尝试我能想到的任何方法。

我试过这样的模式:

我错过了什么?

Header 指令接受两个不同的参数以执行替换。执行全局匹配的那个有一个尾随星号 edit*。来自 documents:

The edit form will match and replace exactly once in a header value, whereas the edit* form will replace every instance of the search pattern if it appears more than once.

您需要 edit* 如:

Header edit* Content-Security-Policy , ;