Google Analytics - Redundant Hostnames

Submitted by admin@soz on Fri, 01/17/2020 - 21:41

If we have a redundant hostname, Google Analytics will tracking our domain and independently. This means that our pages will be split across two URLs even if they provide the same content.

To solve this problem (Redirect non-www to www) - the best way is by Fix Redundant Hostnames with 301 Redirects.
To do that, we have to edit the .htaccess file by add this command..(on Apache server)
To locate this file, we have to login to CPanel - looking the '<IfModule mod_rewrite.c>' and add the following lines as below and save.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]

This one for sub-domain:-

RewriteEngine On # This line may already exist # Rewrite all requests to the 'www' version
 RewriteCond %{HTTP_HOST} ^domainname\.com$ [NC]
 RewriteRule ^.*${REQUEST_URI} [R=301,L] 

Note: domainname must to change to your real domain name


  • This is for site with https
  • Creating these redirections will also help search engine bots to crawl your website more efficiently

More detail: