Search code examples
.htaccessgoogle-analyticshttp-status-code-301

Redirect with URL parameter added


In order to see in Google Analytics how many 301 forwards happen from olddomain.com to newdomain.com I understand that I can add a url parameter

However the following doesn't seem to work on the homepage, only subpages:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
  RewriteRule (.*)$ http://newdomain.com/$1?utm_source=olddomain.com&utm_medium=redirect [R=301,L]
</IfModule>

Your help greatly appreciated!


Solution

  • Campaign tracking requires 3 parameters: utm_source, utm_medium, and utm_campaign

    Currently, you are only including utm_source andutm_medium which is probably why you are seeing inconsistent results.

    See Tracking 301 Redirects with Google Analytics for this example:

    RewriteRule ^$ http://www.lanevance.com/?utm_source=redirects&utm_medium=lanevance.me&utm_campaign=301_Redirects [R=301,L]

    The URL Builder from Google is also very helpful.