Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to create a simple "secret" mod_rewrite redirect (not shown in user's browser address box) to redirect:

http://www.mydomain.com/code -> http://www.mydomain.com/?utm_source=redirect&utm_medium=link&utm_campaign=code

And if possible also add www. if missing, so:

http://mydomain.com/code -> http://www.mydomain.com/?utm_source=redirect&utm_medium=link&utm_campaign=code

I tried:

# Custom rewrites
RewriteRule ^code/?$ /?utm_source=redirect&utm_medium=link&utm_campaign=code [L,NC,QSA]

My .htaccess mod_rewrite other rewrite rules look like this:

# redirect to www form
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^([a-z]+)\.%{HTTP_HOST} [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,QSA]
# rewrite file to file.php, ignore directories, ignore existing non-php files
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L,QSA]

I tried to put the custom rewrites section either in front of all the other rules or in the middle or remove [QSA]/[NC], but the problems are that it either

  • Doesn't rewrite secretly
  • Doesn't show rewrites in Google Analytics (I'm sensing it's because it does some other rewrite before and therefore Google Analytics won't count the campaign)

What am I doing wrong?

share|improve this question
    
Google Analytics is JavaScript code that looks at the URL that the user sees. If you try too keep this information secret, then Analytics won't be able to see it either. –  Stephen Ostermiller Jan 15 at 3:40
add comment

1 Answer

up vote 0 down vote accepted

It looks like it is not possible to do the redirect using mod_rewrite as it is processed before the page even starts loading and Google Analytics is JS which is fired only after the page starts loading.

BUT it is possible to create a JS redirect called after Google Analytics pageview has been tracked.

I have found more about that at this article: http://cfsimplicity.com/61/removing-analytics-clutter-from-campaign-urls

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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