How to Redirect Non-WWW to WWW using .htaccess file

How to Redirect Non-WWW to WWW using .htaccess file
Like Tweet Pin it Share Share Email

There is no matter if you use www or non-www site. Search engine doesn’t stop you to use one of them. But if you’re using a non-www and want to redirect all your site into www version or www to non-www with htaccess then here is the solution for you.

In all website root directory, there will be a .htaccess file exists. So you can easily redirect all of the requests for yourdomain.com domains to www.yourdomains.com by modifying it.

redirecting-non-www-to-www-with-htaccess

Many people trying to find the solution to force either the www or non-www of their sites. Now follow below guides to learn how to force non-www to www in .htaccess OR www to non-www in your webhosting Cpanel account.

How to Redirect Non-WWW to WWW in .htaccess File

(NOTE: I’ll Use iPage WebHosting CPanel)

Step1. Log In to your webhosting CPanel account and go to “File Manager”.

control-panel-ipage

Step2. Click on the Settings at the top right corner.

ipage settings tab

Step3. Make sure you’ve checked the System Files and other options like hidden files etc.

system-files-ipage

Step4. Now open the root directory folder where you install your site and find the .httaccess file. Go to its menu and click on Edit option.

edit .htaccess file

Step5. Now you’re comes in text editor. Simply copy the below code to force non-www to www version. Be sure that to replace ‘yourdomain.com’ with your actual domain name.

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

How to Force WWW to Non-WWW in .htaccess File in CPanel

Above, I’ll show you how to redirect your non-www website address to www version using .htaccess file into your webhosting CPanel. Now here I’ll show you how to force www to non-www in .htaccess file.

Follow all the above steps, just copy the below piece of code and replace instead of upper one.

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

Now, when you type in your domain name with either www in front or not, it should display as you have set it in the .htaccess file. I hope you may be easily understand this amazing SEO trick that helps you to easily force and redirect your website site address in www or non-www version. If you face any problem comment below and I’ll resolved it as soon as possible.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *