It’s easy adding 301 redirects to your website using Apache’s htaccess. A 301 redirect is the most efficient and Search Engine Friendly method for web page redirection. It’s not difficult to implement and will preserve your search engine rankings as well.
So, basically how this works is when someone tries to access your website without the (www), it will redirect the URL to your website with the www.
To implement this for your website follow these instructions:
- Open up notepad or any other text editor and copy and paste the commands below.
- Change (yourdomain) to your domain name.
- Save the file with this name: (.htaccess). There is no file name.
- Upload it to the root directory of your website.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]