---
title: "Handling redirects while keeping web analytics/UTM query parameters"
date: "2024-05-17T00:37:10+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/93296-handling-redirects-while-keeping-web-analyticsutm-query-parameters"
id: "f8e1f050-c3d4-4796-bd33-b4ba22b494ad"
---

Background 
-----------

The Acquia platform, as a means to maximize performance via the Varnish caching layer, removes web analytics parameters from URLs (for example, Google Analytics' `**utm_source**` and others).

Our documentation at [https://docs.acquia.com/cloud-platform/performance/varnish/querystrings/](/node/56442) has a general explanation of how and why Acquia strips these parameters.

However, if your application requires issuing redirects that need to keep these parameters, then you will need to implement some additional strategies.

Strategies
----------

To properly have a site effectively handle **utm** parameters while maintaining the best performance (with our Varnish stripping), various strategies are recommended. You should evaluate each one (and potentially use more than one at the same time) to determine which are best for your particular use case.

### 1) Ensure your site advertises https:// URLs everywhere

If search engines, ads, emails, etc. still use **HTTP** URLs, you should work on changing that and stick to using **HTTPS** URLs only to minimize the need for handling redirects at your application.

### 2) Handling redirects from Drupal

**Note**  
**Because this option requires that you turn off Drupal page caching for parts or all of your site, you will need to handle with care.**

For the very specific use case of handling **utm** parameters for redirects, built using the [Redirect](https://www.drupal.org/project/redirect) module (and, with page caching disabled) you can use the [https://www.drupal.org/project/acquia\_analytics\_redirects](https://www.drupal.org/project/acquia_analytics_redirects) module. It will properly redirect URLs using the hidden `**X-Acquia-Stripped-Query**` header sent from Varnish to the Apache/Drupal backend.

**Note**  
You should read the [Acquia Analytics Redirects project page/documentation](https://www.drupal.org/project/acquia_analytics_redirects) for more details.

### 3) Handling redirects from .htaccess

Sometimes, a `.htaccess` file which includes **HTTP to HTTPS** or other redirects may not include logic to handle URLs with Google Analytics utm\* parameters. The way around this is:

A workaround involves using the `**X-Acquia-Stripped-Query**` header to build the destination URL  
and avoiding caching of these redirects by marking them as 302s (instead of 301).

Below is an example `**.htaccess**` section that can handle **HTTP to HTTPS** redirects while including the parameters:

    # EXAMPLE: NOT MEANT TO USE AS-IS; do edit and test according to your site.
    #
    # HTTP -> HTTPS redirect + Keep web analytics parameters
    #
    #   Only triggers when the Acquia Varnish layer has stripped parameters
    #   like 'utm_*'. 
    #   See https://docs.acquia.com/acquia-cloud/performance/varnish/querystrings/
    #
    #   This redirect is a 302 to avoid caching at the Varnish layer.
    #
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTP:X-Acquia-Stripped-Query} .+
    # ... you can add more conditions here ...
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}?%{HTTP:X-Acquia-Stripped-Query} [L,R=302]

### 4) Use HSTS to avoid HTTP requests

You can also enable [HSTS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security) on your site, which sends a special header that modern browsers will use to always use **https** to connect to your site (no redirect needed!). For information about how to enable [HSTS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security), see [this article](/acquia-cloud-platform/help/93566-how-enable-hsts-your-drupal-site "How To enable HSTS for your Drupal site").