WWW to Non WWW Redirection using htaccess in WordPress Website

4.6/5 - (14 votes)

What Is URL Redirectoion?

This article is all about www to non www redirect Using htaccess. Let’s suppose you have just designed a website (https://techydirver.com), there are high chances of having several URLs for this single domain.

Unfortunately, Google doesn’t like it because when a user hits on your URL with different-different protocols like WWW or NON-WWW your website shows errors (This Website Cant be accessed!). 

This is not a good signal, Google considers these URL’S as duplicate versions of your website. Fortunately, we have the solution to fix this issue. We can redirect all the other protocols to the single protocol which is HTTPS with a few lines of code. This process is called URL Redirection.

Why URL Redirection Is Important?

This is a very serious issue you should fix it as soon as possible because when a user visited our website and facing an error like this website can’t be reached! this means you are losing your visitor, losing visitor is directly connected with your pocket and I am sure you won’t like it and even Google also doesn’t like it, Google considers them a duplicate version of your website.

We have provided a few lines of code with the guide, follow and fix this error.

WWW to Non-WWW Redirection using htaccess

Before this, you have to configure your server with WWW. follow the steps provided below-

  • First of all, log in to your domain registrar if you are using Cloudflare then you should log in to your Cloudflare account.
  • Then go to the DNS Management section.
  • And UPdate your A Records, basically point your IP.
  • To get your IP visit https://whatsmydns.net.
  • Enter your URL and select A simple click on search.
  • Copy the first IP and paste it into your DNS Management Record.
  • Then click on save changes and yes you have done.

Sometimes it took time to get implemented so don’t panic keep waiting for at least 24 or 48 hours.

Now it is time to permanently redirect to WWW to Non-WWW Redirection using htaccess in WordPress Website. In order to do this simply copy this line of codes and paste it into your .htaccess file.

#  301 redirect www to non-www

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

# If you want the WWW # 301 redirect to www

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

//

How To Access .htaccess file

There are two ways how you can access your .htaccess file both are the same. You can access it with either a WordPress plugin or directly from Cpanel. If you are using the WordPress plugin then download WP File Manager. 

Install this plugin this will create a file manager to your WordPress dashboard and you can simply update your .haccess file from there. If you are still facing issues while updating our .htaccess file make sure to watch this video till the end.

Final Verdict

I hope this article was helpful for you. Follow the provided steps and I am sure you would be able to fix this serious issue.

If you are still facing any issue regarding WWW to Non WWW Redirection or any Technical SEO error then you should visit our youtube channel where we have made a sufficient number of videos about Technical SEO for free! watch them and learn.

Lastly, I would say Happy Blogging and Happy Ranking!.


One Request?

I worked hard on this post to help the blogging community. It would help me a lot if you consider sharing it on social media networks. Because Sharing Is Caring.. ♥️

Sharing Is Caring...
Avatar of ANAND

An aspiring MCA student formed an obsession with Blogging, SEO, Digital Marketing, and Helping Beginners To Build Amazing WordPress Websites.

Leave a Comment