My goal is to \"whitelist\" certain querystring attributes and their values so varnish will not vary cache between the urls.
Example:
Url 1: http:/
There's something wrong with the RegEx.
I changed the RegExes used in both regsub calls:
sub normalize_req_url {
# Clean up root URL
if (req.url ~ "^/(?:\?.*)?$") {
set req.url = "/";
}
# Strip out Google Analytics campaign variables
# They are only needed by 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]+|mr:[A-z]+)=") {
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|utm_[a-z]+|mr:[A-z]+)=[%\._A-z0-9-]+&?", "");
}
set req.url = regsub(req.url, "(\?&|\?|&)$", "");
}
The first change is the part "[%._A-z0-9-]", because the dash functioned like a range symbol, that's why I've moved it to the end, and the dot should be escaped.
The second change is to not only remove a question mark at the remaining URL, but also an ampersand or question mark and ampersand.