Most websites can be reached with two addresses. One address has the www in it, like https://johnchow.com, while the other address has the www missing; https://johnchow.com.
From a SEO standpoint, it is better to pick one domain format and stick with it. This way you don’t have Google giving separate PageRank for two URLs that point to the same page. The easiest way to do this is by logging into your Google Webmaster Tools account and setting a preferred domain.
The preferred domain is the one that you would liked used to index your site’s pages (sometimes this is referred to as the canonical domain). Links may point to your site using both the www and non-www versions of the URL (for instance, http://www.example.com and http://example.com). The preferred domain is the version that you want used for your site in the search results.
Once you tell us your preferred domain name, it may help us determine PageRank for your site more accurately.
Adding a 301 Redirect
After you set the preferred domain, you should force everyone to use this domain with a 301 redirect. You do this by editing your root .htaccess file. I want everyone visiting John Chow dot Com to do so with the www in the URL. To force this, I open my .htaccess file and enter the following codes:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.*)\.johnchow\.com$ [NC]
RewriteRule ^(.*)$ https://johnchow.com/$1 [R=301,L]
You will need to replace johnchow.com with your site URL. What the above does is redirect all johnchow.com to www.johnchow.com. How does this help with search ranking?
By maintaining one preferred domain format, you ensure linking consistency. If you have 10 sites linking to your article with a www and another 10 sites linking without the www, you present Google with two pages, which will not receive the same weight as 20 sites linking to the preferred domain. The above .htaccess code will ensure that everything goes to the domain format you want.
Note – the .htaccess redirect works only on Linux servers with the Apache Mod-Rewrite module enabled.