
.htaccess 301 Redirect
One of the simplest way to redirect is the use of .htaccess redirect. .htaccess redirect helps in redirecting a non www domain to www domain. Means it will redirect the domain.com to www.domain.com. For this redirection we need to create a simple .htaccess file with the code below.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
You need to replace the domain.com and www.domain.com with your website's actual name. Create the .htaccess file with the code above and place it in the root directory of your website.
Note* The .htaccess method given above works only on Linux servers having the Apache Mod-Rewrite module enabled in it.