“ Header append Vary User-Agent”与“ Header append Vary User-Agent”相反,如何删除“ User-Agent”来自“ Vary”的字符串? [英] What's the opposite of "Header append Vary User-Agent", how to remove the "User-Agent" string from "Vary"?
问题描述
我知道我可以将 User-Agent
添加到 Var
http标头中,并在其中添加此行。 htacess:
I know that I can add the User-Agent
to the Vary
http header with this line in my .htacess:
Header append Vary User-Agent
但是如何从 Var
标头中删除 User-Agent
But how can I remove the User-Agent
from the Vary
header if it is already set?
根据 mod_headers文档中有一个 append
选项,但没有等效的删除选项。
According to the mod_headers doc there is an append
option, but no equivalent "remove" option.
推荐答案
下面是简单的答案,但是您需要一些技巧来避免发送空的Vary:标头(尝试避免出现偏执狂) )
Simple answer below, but you need some shenanigans to avoid sending an empty Vary: header (try to avoid it out of paranoia)
Header edit Vary (.*)User-Agent(.*) $1$2
# Remove leading or trailing ',' without making things complex above
Header edit Vary ^,?(.*),?$ $1
# 2.4-only: remove empty Vary header
Header unset Vary "expr=resp('Vary') =~ /^$/"
x-never-match不太可能到曾经使用过的标题名称。
x-never-match can be any unlikely-to-ever-be-used header name.
这篇关于“ Header append Vary User-Agent”与“ Header append Vary User-Agent”相反,如何删除“ User-Agent”来自“ Vary”的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!