如果 URI 包含单词,则在 Apache .htaccess 中设置标头

Paw*_*ała 2 regex apache .htaccess

.htaccess如果 URI 包含单词/account,我想设置一个自定义标头,例如它应该与以下 URI 匹配http://www.example.com/accounthttp://www.example.com/account/address

我尝试使用以下代码,但它不起作用:

<If "%{REQUEST_URI} =~ /account/">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
</If>
Run Code Online (Sandbox Code Playgroud)

但是,当我删除 if 语句时,标题设置正确。

anu*_*ava 6

您可以使用THE_REQUESTinIf条件来避免此块被修改REQUEST_URI

<If "%{THE_REQUEST} =~ m#\s/+account[/?\s]#">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
</If>
Run Code Online (Sandbox Code Playgroud)