Hello Folks, hope you are doing well, In this article I am share with you that how can you redirect your WordPress Website from WWW to non-WWW and vice versa.

What is WWW to non-WWW redirection

Suppose you have one domain, let’s name it abc.com, you start your own blog or may be your business whatever it is. After that it is required to submit your site to every search consoles, sometimes it is happened that abc.com is working perfectly but www.abc.com is not opening or vice versa.

From SEO perspective, then there are two version of your same site which is not right for your website ranking.

First you have to decide that which version you need, www or non-www, it is depends on you, and follow the next steps.

WWW to Non-WWW .htaccess redirection

If you want to redirect WWW version of  your website to non-www by using .htaccess file follow these stapes

  1. Open your hosting file manager go to public_html and after that your domain folder. Also you can use file manager plugin to access the .htaccess file.
  2. In the domain root folder you will find the .htaccess file. You need to edit it but make sure to get a backup of this file before editing it because it is very much crucial for your site.
  3. Copy the below written code and paste it before # End WordPress.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain.com
RewriteRule (.*) https://yourdomain.com/$1 [R=301,L]

Replace “yourdomain.com” to your real domain name.

DNS setup

If you using Cloudflare you need to setup a DNS CNAME record, just follow the steps. Go to your DNS record and create a CNAME record.

Name: www

Content: yourdomain.com (replace with your own domain name)

TTL : auto

Non-WWW to WWW .htaccess redirection

Do the same process 1, 2, 3 like before and paste the following code.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]

Conclusion

Domain redirection is very much necessary for your domain because if you have two versions of your website (www and also non www) that is not good for SEO perspective and also not for your visitors