If not, setting redirect www to non www or vice-versa will create duplicity of site. Because google thinks the www and non-www version as different pages.
How to avoid duplicity of site using Google webmaster tool?
To avoid that, we should set the preferred domain (www or non-www).It tells the google webmaster which domain to crawl and index. Otherwise, our site gets penalized in search engines. We should ensure only one URL (www or non-www) is accessible and the other one is redirected.
Sometimes, we may lose valuable search engine traffic due to incorrect configuration. When any search engines come to the site for crawling, it checks for any redirect setup. If not able to follow any redirects, it will think the site has no contents.
If we have specifieddomain as http://www.example.com and we find links to our site is formatted as http://example.com,We will be treated as a http://www.example.com.
Setup you site using google webmaster tool:
Step 1: First, you need to submit your website to google webmaster tool and verify the ownership of your domain with www and without www. Once your ownership was verified, login to your website domain dashboard under the google webmaster tool.
Click on the gear icon is at the top right corner of and then click on the site settings.
here, you can set up your preferred domain. You need to select the www or non-www version of your domain.
Once you set your preferred domain. You have to set up 301 redirection, if you have a WordPress blog, don’t worry about it, By default WordPress will do it.For other users don’t forget to change.
Step 2: Open your file manager of your domain and create a file and name it as .htaccess.Copy and paste the following code and edit your domain name and save the file.
Setup guide: youtube link
If you have preferred www version, use this:
If you have preferred non-www version, use this: