![](https://cloudrocket.top/wp-content/uploads/2018/09/how-to-redirect-www-to-non-www-and-vice-versa-blog.jpg)
In one of my earlier articles, I talked about URL redirect www, covering why website owners choose to redirect their websites to a different domain, the difference between Permanent Redirect (301) and 302 Redirect, its implications on SEO and, in turn, your website. Once you’ve decided to redirect your website, it is equally important to decide, how you want to execute it.
Technically there are two URLs, redirect www and non-www and, although these two URLs are different, if you have both of them redirecting to the same web page it may confuse users and affect your SEO and ranking. However, before delving into which URL to choose and how to redirect www to non-www and vice-versa, let us first see the difference.
Redirect WWW and Non-WWW: The Difference
WWW:
- ‘www’ stands for ‘world wide web’ and websites beginning their domain name with ‘www’ are the most common choice for any website.
- The prefix acts as a hostname, easing the process of adding DNS records when adding multiple sub-domains.
- Example of websites prefixing www: www.google.com, www.cloudrocket.top and so on redirect the user to the www version of their website.
Non-WWW:
- These days having redirect www as a prefix to your domain name isn’t compulsory and most websites these days have started using the non-www version. However, non-www domain names are known as naked domains.
- Though these domain names don’t have a technical edge, they prevent the owner from creating cookieless subdomains. The advantage with a non-www version the prefix is usually the representation of the page the user is currently viewing.
Irrespective of whether you choose to prefix www to your domain name or not, the HTML pages are still interconnected and accessible over the internet. Although, neither are there direct implications on the website’s SEO nor is one version preferred over the other, however, if the users are redirected to either version, it might affect the overall SEO. A simple way to prevent this is by setting up the preferred preference on google.
Follow these steps to update your preference for Google Search Engine:
- Go to Google Webmasters Tools
- Select your website
- Click on the Settings icon on the extreme right side of the page
- In the drop-down menu, select ‘Site Settings’
- Here, set your ‘Preferred Domain’ (www or non-www)
Apart from setting your preference for Google, you can even redirect www site to non-www and vice versa. We’ll be covering how to go about it for two servers, Apache (Linux) and IIS (Windows).
How to redirect www to non-www on Apache server: Linux Hosting
- For making changes on the Apache server, you’ll need to edit the .htaccess file
- Apache server is available on Linux powered Hosting and can be accessed via cPanel
- Login to your reseller account → Access cPanel of the domain you want to redirect
- In your cPanel, find File Manager
- Inside your File Manager, go to public_html and search for .htaccess file.
- If there isn’t a .htaccess file create a new one by clicking on ‘+ File’
- Insert the following code in the .htaccess file
RewriteCond %{HTTP_HOST} ^www.yoursitedomain.com [NC]
RewriteRule ^(.*)$ http://yoursitedomain.com/$1 [L,R=301]
How to redirect non-www to www on Apache server:
- Follow the above steps till step 6
- Instead of the code mentioned above in step 7, insert the following code in the .htaccess file should you want to redirect non-www to www
RewriteCond %{HTTP_HOST} ^yoursitedomain.com [NC]
RewriteRule ^(.*)$ http://www.yoursitedomain.com/$1 [L,R=301]
Should you already have a .htaccess file and ‘RewriteEngine On’ line in it, then all you need to do is insert the code below that line.
* If you have SSL certificate installed on your domain, in the code instead of ‘http’ write ‘https’.
Redirect www to non-www on IIS server: Windows Hosting
- For making changes on the IIS (Internet Information Services) server, you’ll need to edit the web.config file
- IIS server is available on Windows-powered Hosting and can be accessed via Plesk ( not available with us)
- Login to your reseller account → Access Plesk panel of the domain you want to redirect
- In your Plesk panel, find File Manager
- Inside File Manager go to httpdocs and search for the web.config file.
- If there isn’t a web.config file create a new one by clicking on ‘+ New’
- Insert the following code in the web.config file. If you already have a web.config file then don’t mention the ‘configuration’ tag in your code.<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect to non-www” stopProcessing=”true”>
<match url=”.*” >
<conditions>
<add input=”{HTTP_HOST}” pattern=”^yoursitedomain\.com$” />
</conditions>
<action type=”Redirect” url=”http://yoursitedomain.com/{R:0}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Redirect non-www to www on IIS server:
- Follow the above steps till step 6
- Instead of the code mentioned above in step 7, insert the following code in the web.config file should you want to redirect non-www to www<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect to www” stopProcessing=”true”>
<match url=”.*” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^yoursitedomain.com$” />
</conditions>
<action type=”Redirect” url=”http://www.yoursitedomain.com/{R:0}”
redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
* If you have SSL certificate installed on your domain, in the code instead of ‘http’ write ‘https’.
If you have different URLs and still haven’t set the preferred URL, what are you waiting for? I suggest you follow this guide on how to redirect www to non-www and vice-versa today!