Redirecting WWW to NON-WWW URLs might be an easy task for professionals but for beginners, it is a very time-consuming and hectic process using a .htaccess file.
Most of the bloggers are new in this field and sometimes they even don’t know where to locate the .htaccess files or how to connect to their server or shared hosting.
Why do you need domain redirection?
WWW and NON-WWW are two different domains for Google. If you do not use redirection it will affect your website SEO and user experience.
Let’s say you have installed your site on http://example.com, Now if a user visits http://www.example.com he will see a “website not found” error because there is no website on www subdomain. To force redirect of www URLs to non-www URLs, it needs a redirection rule so that the user lands on the right destination even if he types www URLs of the website.
Easy way to achieve domain redirection from WWW to NON-WWW and NON-WWW to WWW.
Important: WWW to NON-WWW redirection will work only if the website is installed on the NON-WWW version.
Now if you have your website installed on the NON-WWW version of the domain and you want to redirect WWW URLs to NON-WWW URLs then follow these steps.
Redirecting WWW URLs to NON-WWW URLs using the DNS setting.
This method is the easiest one because everybody has control of their domain management account and they can easily reach there.
Here I am Taking the Namecheap domain account for demonstration but it can work for all the domain registrars e.g. Bluehost, Hostgator, Godaddy, etc.
- Login to your domain registrar account.
Go to DOMAINS where you can list of domains you own. And click on MANAGE next to your target domain.
- Now go to ADVANCED DNS SETTING
Click on ADVANCED DNS
- Create a CNAME record
HereClick on ADD NEW RECORD
Under TYPE select CNAME RECORD
Under HOST type www
In VALUE type your domain name without www and click save.
Now all the steps are completed please wait for a few minutes as domain propagation takes some time. Don’t forget to clear your web browser cache and cookies before testing redirection.
You can also check your domain redirection using an online tool Whatsmydns. Type your domain with www prefix e.g. www.yoursite.com and select CNAME in the second field. And click on the Search button.
As in my case, you can see in the picture below my www URL is successfully redirecting to the non-www version.
If you have your website installed on the WWW version of the domain and you want to redirect NON-WWW URLs to WWW URLs then follow these steps.
Important: NON-WWW to WWW redirection will work only if the website is installed on WWW version
Redirecting NON-WWW URLs to WWW URLs using the DNS setting.
The First and the Seconds steps are similar to the previous case.
In the third step, you will make some changes
As shown in the above picture
- Edit the A Record, in the HOST field put WWW and in the value field put the IP address of your server.
- Create a new CNAME Record and type @ in the Host field and in the value type the domain name as www.yourdomain.com.
Now all the steps are completed please wait for a few minutes as domain propagation takes some time.