清漆。 如何忽略url特殊参数以返回缓存但保留查询字符串的原点?清漆。如何忽略url特殊参数以返回缓存但保留查询字符串的原点?
domain.com/?utm1=232&urm2=2323
我需要为GA遗留此utm,但忽略返回缓存页面。
清漆。 如何忽略url特殊参数以返回缓存但保留查询字符串的原点?清漆。如何忽略url特殊参数以返回缓存但保留查询字符串的原点?
domain.com/?utm1=232&urm2=2323
我需要为GA遗留此utm,但忽略返回缓存页面。
您可以设置一个包含相关url的标头来缓存并更改varnish散列对象的方式。
sub vcl_recv {
...
# Remove the params you don't want from the query string and set it to a
# temp header (Varnish does not have variables)
set req.http.x-cache-url = regsub(req.url,"(utm1=.*&|utm1=.*)", "")
...
}
# Below is the default vcl_hash but swapping the req.url for req.http.x-cache-url
sub vcl_hash {
hash_data(req.http.x-cache-url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (lookup);
}
这样做,你将能够保持您的查询字符串,因为它是和你仍然能够提供同样的缓存不同PARAMS。
注意即regsub是你操纵params的地方。随意根据您的需求进行更改。
更好的解决方案是重写传入的URL,而不是引入不必要的VCL。这也将照顾所有的谷歌相关的JavaScript变量,而不仅仅是utm_ones:
if (req.url ~ "(\?|&)(gclid|utm_[a-z]+)=") {
set req.url = regsuball(req.url, "(gclid|utm_[a-z]+)=[-_A-z0-9\+\(\)%]+&?", "");
set req.url = regsub(req.url, "(\?|&)$", "");
}
查看更多在原来的职位上stripping Google Analytics variables with Varnish。