How to Redirect non www to www using .htaccess (Simple)

Guys, In today’s post, I will discuss how to redirect non www to www using .htaccess (Simple). In this post, you will learn how to redirect all non-www links to www links. That means if someone press letslearnnow.net in the URL bar of their browser, they will be automatically redirected to www.letslearnnow.net  So let’s learn how to do this with .htaccess

Redirect non www to www using .htaccess:

Find the .htaccess file in your root folder. If you are using Cpanel, click “Show hidden files” and check if there is already an existing .htaccess file. If you don’t find any existing file, add a .htaccess file in the root folder of your website. Then paste the following code.

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

Don’t forget to change the domain according to your domain name. Replace yourdomain.com with your domain name. That’s it. Now if someone enters your domain without www, he will be redirected to www.yourdomain.com.

Redirect non www to www in a subfolder using .htaccess:

If you are interested in using www in your subfolder too, you can use the same code. Just use your subfolder name at the end of the URL.

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

Redirect Non www to www -minIf you would like to use https instead of HTTP, then you can change the HTTP to https. But if you have another type of SSL plugin installed in your website, use a plain HTTP. Because using https may cause redirect loop with a plugin. Hope you understand.

If you are using WordPress to create your website, I suggest using “Really Simple SSL” plugin. Either you can use “Cloudflare + Really Simple SSL” for more security. Cloudflare is entirely free to set up and no monthly cost. Cloudflare is a CDN network which prevents your site from malicious robots too.

If you are not sure what plugins to install as a beginner, you may read the detailed post about creating a WordPress website from scratch.

LLN Team

About The Author : LLN Team

We are LLN Team promise you to provide you useful information about website and blog creation. We will focus on WordPress and other essential needs. Keep browsing Lets Learn Now. Cheers

Leave a Reply

Your email address will not be published.

Please post a relevant comment and make the conversion informative.