Redirect to www using htaccess redirect

This tutorial will show you how to redirect to www using htaccess redirect

Understaning the usage of .htaccess.

1.Create a .htaccess file with the below code, (With Notepad)

2.Please ensure that all requests coming in to yourdomain.com will get redirected to www.yourdomain.com
3.The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

 

.htaccess code:

RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

4.Please REPLACE domain.com and www.newdomain.com with your actual domain name.

5.Save the notepad and upload the .htaccess file to the FTP through FIlemanagner or Filezilla.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.