apache 如何将string替换为mod_substitute的替换部分中包含空格字符的字符串

7tofc5zh  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(182)

在我的apache 2.4 httpd服务器中,我想使用mod_substitute在我的响应中添加这个小的javascript片段。
就像这样-

<Location /styles.blahblah.css>
            AddOutputFilterByType Substitute text/css
            Substitute s|::-webkit-scrollbar{width:16px}|'.button-group :first-child{display:none}::-webkit-scrollbar{width:16px}'|ni
    </Location>

但问题是,这会导致编译错误,因为在替换部分button-group后面有空格。如果我删除空格,它会编译,但这不是我想要的。
我试图定义一个变量并在替换部分使用它,但如果变量也有空格,它会导致同样的错误。如果我从变量中删除空格,它不会抛出错误。

Define css_substitution ".button-group :first-child{display:none}::-webkit-scrollbar{width:16px}"

     <Location /styles.blahblah.css>
            AddOutputFilterByType Substitute text/css
            Substitute s|::-webkit-scrollbar{width:16px}|${css_substitution}|ni
    </Location>

有没有办法在mod_substitute的替换部分使用空格字符?文档中没有任何地方说我们不能在替换中使用空格字符。

vzgqcmou

vzgqcmou1#

我可以通过将整个Substitute语句用双引号括起来来实现这一点,就像这样-

<Location /styles.blahblah.css>
        AddOutputFilterByType Substitute text/css
        Substitute "s|::-webkit-scrollbar{width:16px}|'.button-group :first-child{display:none}::-webkit-scrollbar{width:16px}'|i"
</Location>

相关问题