Information for: DEVELOPERS   PARTNERS

Stripping query strings in Varnish

Many web analytics software packages (such as Google Analytics) enable you to measure traffic by adding unique HTTP query string parameters to URLs. By modifying a base URL (such as https://www.example.com/path/to/page) and adding query string parameters, you can measure user behavior and engagement. For example, the following URL contains two common query string parameters (utm_medium and utm_source) appended to the base URL:

https://www.example.com/path/to/page?utm_medium=notification&utm_source=email

On Acquia Cloud, Varnish® strips the query strings from popular web analytics software packages and then stores a cached version of the page according to the base URL, instead of the full URL with appended query strings, without breaking the reporting to your web analytics software. Acquia Cloud will serve the version of the page stored in Varnish cache for subsequent requests that match the base URL, varying only by the query string parameters, which enables measurable marketing campaigns while preserving website performance.

For example, Acquia Cloud will display each of the following webpages as the same cached webpage (https://www.example.com/path/to/page) to a visitor:

  • https://www.example.com/path/to/page?utm_medium=notification
  • https://www.example.com/path/to/page?_ga=1.000001
  • https://www.example.com/path/to/page?utm_medium=notification&utm_source=email
  • https://www.example.com/path/to/page?utm_medium=notification&utm_source=facebook

When serving a webpage to a visitor, Varnish will perform the following steps:

  1. Strip the query string parameters from the requested URL.
  2. Add an X-Acquia-Stripped-Query header that contains the query string parameters to the HTTP request.
  3. Redirect the request to both the non-bare and https:// prefixed version of the domain.
  4. If permitted by caching policy, cache the returned webpage according to the base URL.
  5. Serve the content to the visitor.

Note

Acquia recommends using both the non-bare and https:// prefixed version of your domain to prevent unnecessary redirects, reducing load on your subscription’s servers.

Preventing the caching of query-stripped requests

If the X-Acquia-Stripped-Query header is present on webpages that should not be cached, create a custom Drupal module to add the following header to the responses to prevent caching:

Cache-Control: must-revalidate, no-cache, private

For tools to inspect the HTTP response headers of a webpage, see browser developer tools. For methods of controlling caching for certain types of responses, see Set max-age headers for specific pages, files, or paths.

Important

Use caution when removing caching from responses, as doing so can have negative performance implications.

Using the X-Acquia-Stripped-Query response header in Drupal

For uncacheable requests where the contents of X-Acquia-Stripped-Query can be used by parsing the $_ENV['HTTP_X_ACQUIA_STRIPPED_QUERY'] variable with the following Drupal functions: