I hope you can assist me with this! I've recently changed the preferred domain for my site https://example.com. Unfortunately, after doing so, it appears that views/visits are no longer being recorded by Google Analytics. I've edited the URL in GA's Admin settings to indicate that it is now https://example.com - perhaps it just needs some time to settle in?

Also, I'm not quite sure if I've set up the 301 redirect correctly after setting my preferred domain.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

If I have an HTTPS site, do I need to add the 's' to the sections that contain 'HTTP'?

  • Is that your actual htaccess?
    – John Conde
    Jan 13, 2018 at 16:46
  • Hi John - no, it was just a template that I used. I replaced 'yourdomain' with my site's information!
    – Ann
    Jan 13, 2018 at 17:05
  • 1
    Do you have filter set in Google Analytics? One of the solutions for GA spam is to set a filter so only hits to your domain count in the GA stats. If you have ever implemented such a filter you need to change it now that you are not using the www. Mar 16, 2018 at 11:53

2 Answers 2


Yes, you do need to add the 's'.

Specifically to this line: RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

You can't redirect all visitors to HTTPS when you explicitly redirect them to HTTP!

At a minimum, you need RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

I suggest you look over lines 262 to 413 of this file https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess


That should not happen. When you use a redirect like that it doesn't trigger any JavaScript, not any site load. Hence your analytics shouldn't recognize any action and stop recording stats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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