title: Stripping out select querystring attribute/value pairs so varnish will not vary cache by them
body: <p>My goal is to "whitelist" certain querystring attributes and their values so varnish will not vary cache between the urls.</p>
  
  <p>Example:  </p>
  
  <pre><code>Url 1: http://foo.com/someproduct.html?utm_code=google&amp;type=hello  
  Url 2: http://foo.com/someproduct.html?utm_code=yahoo&amp;type=hello  
  Url 3: http://foo.com/someproduct.html?utm_code=yahoo&amp;type=goodbye
  </code></pre>
  
  <p>In the above example I want to whitelist "utm_code" but not "type" So after the first url is hit I want varnish to serve that cached content to the second url.</p>
  
  <p>However, in the case of the third url, the attribute "type" value is different so that should be a varnish cache miss. </p>
  
  <p>I have tried the 2 methods below (found on a drupal help article I can't locate right now) that did not seem to work. Might be because I have the regex wrong. </p>
  
  <pre><code># 1. strip out certain querystring values so varnish does not vary cache.
  set req.url = regsuball(req.url, "([\?|&amp;])utm_(campaign|content|medium|source|term)=[^&amp;\s]*&amp;?", "\1");
  # get rid of trailing &amp; or ?
  set req.url = regsuball(req.url, "[\?|&amp;]+$", "");
  
  # 2. strip out certain querystring values so varnish does not vary cache.
  set req.url = regsuball(req.url, "([\?|&amp;])utm_campaign=[^&amp;\s]*&amp;?", "\1");
  set req.url = regsuball(req.url, "([\?|&amp;])foo_bar=[^&amp;\s]*&amp;?", "\1");
  set req.url = regsuball(req.url, "([\?|&amp;])bar_baz=[^&amp;\s]*&amp;?", "\1");
  # get rid of trailing &amp; or ?
  set req.url = regsuball(req.url, "[\?|&amp;]+$", "");
  </code></pre>