Author

Analytics Expert. Passionate about SEO and User Experience or what he calls UX-SEO

Follow me on

Redundant Hostnames Warning - Google Analytics

If you are receiving the redundant hostname notification it means that Google Analytics is tracking your domain www.example.com and example.com independently. This means that your pages will be split across two URLs even if they provide the same content.

How to solve redundant hostnames warnings in Google Analytics

For example, considering that I'm receiving this notification and using the URL of this post, that means that Google Analytics is tracking both versions of the URL separately.

  • www.ohow.co/fix-redundant-hostnames-notification-in-google-analytics
  • ohow.co/fix-redundant-hostnames-notification-in-google-analytics

You can prevent this by consolidating both domains into one.

Before proceeding, you have to decide if you preferred to have your domain with or without WWW. There are a few technical differences but in general, It is only a matter of personal preference.

Step 1: Quick Fix for redundant hostnames with a filter in Google Analytics

This will help to consolidate your hostnames in GA quickly. After doing this I also recommend you to follow the second step and make the redirections, since it will give you other benefits related to SEO.

How to fix redundant hostnames in Google Analytics

To fix the notification "redundant hostnames in Google Analytics:

  1. Go to the admin section. 
  2. Click on Filters on the 3rd column VIEW, then click the red button +Add Filter
    Add filter button Google Anlaytics
  3. Enter "Consolidate hostnames" as name and select Custom for filter type
  4. From the radio button list select Search and replace (you might need to scroll a little).
    how-to-fix-the-redundant-hostname-error-in-google-analytics
  5. Configure the filter depending on how you want your hostname to appear.
    • Converting WWW to non-www
      • Filter Field: Hostname
      • Search String: ^www\.
      • Replace String: leave it empty
    • Converting non-www to WWW
      • Filter Field: Hostname
      • Search String: ^yourdomain\.com$
      • Replace String: www.yourdomain.com
  6. Save your filter and continue to the next part (You can click verify this filter before saving to have a quick glance of how it will work)

Step 2: Fix Redundant Hostnames with 301 redirects

This part of the guide is more technical. The following configuration files are sensitive so it is important to make a backup before making any changes. If you can't locate your files or you don't fell comfortable editing them ask your web developer or hosting provider, they should be able to help you without a problem.

Note: Creating these redirections will also help search engine bots to crawl your website more efficiently.

Fix Redundant Hostnames for Apache Server - .htaccess

To access your .htaccess file, you should go to the root directory in your Cpanel "yourdomain.com/cpanel". Sometimes you have to check "show hidden files".

Once you locate the file add the following lines at the bottom.

Redirect WWW to non-www

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

Redirect non-www to WWW

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

 

Fix Redundant Hostnames for Nginx

Nginx is a little more complex than the htaccess. Once you locate the configuration file add the following lines:

Redirect WWW to non-www

server {
 server_name www.example.com;
 rewrite ^/(.*)$ http://example.com/$1 permanent;
}

Redirect non-www to WWW

server {
 server_name example.com;
 rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}

 

Fix Redundant Hostnames with WordPress/PHP

If for any reason you can't access your configuration files you can use PHP, this is less efficient than the other two.

Redirect WWW to non-www

 <?php if ($_SERVER&#91;'HTTP_HOST'&#93; == 'www.example.com'){
header("Location: http://example.com".$_SERVER&#91;'REQUEST_URI'&#93;);
}
?>

Redirect non-www to WWW

<?php if ($_SERVER&#91;'HTTP_HOST'&#93; != 'www.example.com'){
header("Location: http://www.example.com".$_SERVER&#91;'REQUEST_URI'&#93;);
}
?>

Step 3: What to do after you consolidate your hostnames

Independently from the method you used, once you have made the necessary changes, go to your Google Analytics click in the redundant hostname notification and click on the blue text "Check Again"

This will change the status to pending verification

And after GA confirms that everything it's ok the notification will change to resolved.

Google Analytics Notifications Resolved - redundant hostnames

 

Author

Analytics Expert. Passionate about SEO and User Experience or what he calls UX-SEO

Follow me on
Be the first to comment :)