Stripping out select querystring attribute/value pairs so varnish will not vary cache by them

前端 未结 7 1055
名媛妹妹
名媛妹妹 2020-12-29 10:57

My goal is to \"whitelist\" certain querystring attributes and their values so varnish will not vary cache between the urls.

Example:

Url 1: http:/         


        
7条回答
  •  一个人的身影
    2020-12-29 11:19

    You want to strip out utm_code but it's not covered by either of the regexps you are using.

    Try this:

    # Strip out specific utm_ values from request URL query parameters
    set req.url = regsuball(req.url, "([\?|&])utm_(campaign|content|medium|source|term|code)=[^&\s]*&?", "\1");
    # get rid of trailing & or ?
    set req.url = regsuball(req.url, "[\?|&]+$", "");
    

    Or if you want to strip all URL parameters that start with utm_ you can go with:

    # Strip out ALL utm_ values from request URL query parameters
    set req.url = regsuball(req.url, "([\?|&])utm_(\w+)=[^&\s]*&?", "\1");
    # get rid of trailing & or ?
    set req.url = regsuball(req.url, "[\?|&]+$", "");
    

提交回复
热议问题