Rewriteengine - .htaccess url rewrite non-www to www


I have found that a standard .htaccess rewrite to avoid canonical issues prevents piwik from tracking referers or pageviews. This is what I put in my .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

It works as intended except it messes up piwik. As soon as I take it out referrers and pageviews are tracked again. Anyone know of a workaround for this problem?