A page redirects to another page using a 301 redirect in a .htaccess file. If I try to access the page from a URL with UTM tagging, after redirection, it removes all UTM tagging.

Is this normal behavior? How can we keep the UTM tagging so that we can see this in our analytics?

Here are some examples:

Example 1:


redirects to:


Example 2:

http://example.com/page.html?utm_source=nosource&utm_medium=nomedium&utm_campgn=nocam&page=1 (Just misspelled utm_camaign to check if utm_ is not just a culprit)

redirects to:


Example 3:


redirects to:


Example 4:


redirects to:


Excerpt from .htaccess:

RewriteRule ^home-living/furniture/([^/\.]+)\.html http://www.example.com/home-living/furniture/filter/cat/$1.h‌​tml [R=301,L]
  • "If I try to access the page from a URL with UTM tagging, after redirection, it removes all UTM tagging." - That reads as if you are clicking a link on a page, and the page the link is on has UTM tagging? But is the link that is being clicked, and ultimately redirected, have the UTM tagging parameters? – MrWhite Dec 29 '16 at 23:58

If your .htaccess has RewriteRules like these:

RewriteRule page.html /another-page.html [NC,R=301,L]

It will always remove querystring parameters, that's default behaviour. You'll have to add QSA flag to your RewriteRule, like this:

RewriteRule page.html /another-page.html [NC,QSA,R=301,L]

Apache mod_rewrite doc

| improve this answer | |
  • tried using QSA but still same behavior – Sandesh Jul 16 '14 at 5:38
  • @ganesh could you post your htaccess or at least an excerpt? – Binarysurf Jul 16 '14 at 15:02
  • 1
    RewriteRule ^home-living/furniture/([^/\.]+)\.html http://www.example.com/home-living/furniture/filter/cat/$1.html [R=301,L] Query string work fine except utm_source, utm_medium and utm_campaign. Why only these removed from query string? – Sandesh Jul 17 '14 at 6:32
  • "It will always remove querystring parameters, that's default behaviour." - Actually, the default is the opposite. If you aren't including a query string on the substitution (as in the example), then the query string is passed through from the request unaltered. However, if you include a query string on the substitution then this will discard the query string on the request. You only need the QSA flag if you explicitly include a query on the substitution and you want to merge this with whatever query string is included on the request. – MrWhite Dec 29 '16 at 23:52

I suggest you to add this line in you .htaccess files if you want to execute and delete the utm analytics from the URL

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} "utm" [NC]
RewriteRule (.*) /$1? [R=301,L,QSD]
<IfModule mod_rewrite.c>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.