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

前端 未结 7 1049
名媛妹妹
名媛妹妹 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:10

    A copy of runamok but i got + instead of %20 in my params so i have added that to my regex

    sub vcl_recv {
        # strip out certain querystring params that varnish should not vary cache by
        call normalize_req_url;
        # snip a bunch of other code
    }
    sub normalize_req_url {
        # Strip out Google Analytics campaign variables.
        # I allso stribe facebook local that are use for facebook javascript.
        # They are only neededby the javascript running on the page
        # utm_source, utm_medium, utm_campaign, gclid, ...
        if(req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|utm_[a-z]+|fb_local|mr:[A-z]+)=") {
            set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|utm_[a-z]+|fb_local|mr:[A-z]+)=[%.+-_A-z0-9]+&?", "");
        }
        set req.url = regsub(req.url, "(\?&?)$", "");
    }
    

提交回复
热议问题