First, what is a redirect?
Redirection is a procedure performed to tell browsers and search engines that the respective site has moved, go here (new www URL) instead. This redirects the users who are looking up for the old URL.
For example:
You have redirected yoursite.com to www.yoursite.com, the redirection will send them to the later version. But why do you have to redirect non-www to www?
www.yoursite.com | yoursite.com |
---|---|
Can handle subdomains a bit better | Slightly simpler, shorter URL |
Can limit cookies to subdomains | Cookies apply to the whole domain |
No impact to SEO if set up right | No impact to SEO if set up right |
This table demonstrates the basic differences between two. One important thing to note down is to always redirect and stick to one, this way all visitors land on the same main page. Also, for consistency and to avoid potential duplicate content issues.
Redirect Non-WWW to WWW using .htaccess
All the websites hosted on Apache web server has an .htaccess file add this file is key to redirecting the site. Here is a step by step guide to help you redirect using .htaccess:
- Access the .htaccess file: Users can find this in the root folder of the website. Eg: /yousite-html/. If this is not working out, we recommend you to make sure all the hidden files are visible in your FTP or file manager.
- Once you have found the .htaccess file, add the below code at the top of the file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Adding this code to the .htaccess file, will constantly check for people who are trying to access your domain without www. When any user's request is found, it redirects them to www version using a 301 permanent redirect.
Make sure to replace yourdomain.com with your actual domain, and use https if your site uses SSL:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Redirect Non-WWW to WWW using Cloudflare
Cloudfare significantly streamlines this process and makes it a little easy for setting up redirects without touching any server files. Here is the step by step process to do the same:
- Access your Cloudfare dashboard
- Now, go to your domain and tap on the Rules tab
- Click “Create Page Rule”
Now to set it up, follow these steps
If the URL matches:
http://yourdomain.com/* (or https://yourdomain.com/* if you use SSL)
Then the settings are:
- Forwarding URL
- 301 - Permanent Redirect
- Destination URL:
- https://www.yourdomain.com/$1
Click Save and Deploy
It is important to make sure that the DNS settings in Cloudfare have the domain that points correctly to your server. Also, ensure the SSL settings are set to “Full” or “Full (Strict)” if using HTTPS.
Now, whenever someone types in:
- yoursite.com
- http://yoursite.com
- https://yoursite.com/page
They’ll be automatically redirected to:
- https://www.yoursite.com
- https://www.yoursite.com/page
When Should You Redirect non-www to www?
1. You have chosen www as your primary version
Every website has a primary version, and if you prefer to use www.yoursite.com as your official website address, then you should redirect. This can be due to branding, tradition, or subdomain handling reasons. Whatever the reason maybe it is always better to redirect yoursite.com to www.yoursite.com to direct all of your audience to one page. If you have 2 sites without redirection, external links will also be affected and also since Google considers them as two different pages, ranking may be affected.
2. To avoid SEO issues
If you have both www and non www versions of your page without any redirections, Google considers them as two different URLs. Now, since the content of these pages is exactly the same, it considers as duplicate content, which in result can impact the page rankings.
3. For accurate analytics
When both pages are live without redirection, your audience will be able to go to both pages. This traffic split can be very confusing to deal with as you have to go through the analytics of both of the pages for data.
4. For consistent branding
The website link is often used across various promotional or informational materials. People in general dont tend to type in www before the address, if your page link is www.yoursite.com , it is more likely that people will search for yoursite.com. Redirection will make it look more polished and professional.
Overview
You should redirect non-www to www if:
- You’ve decided www.example.com is your main domain
- You want to boost SEO by avoiding duplicate content
- You want clean analytics and proper link juice
- You want a consistent, branded experience for users