How to redirect non-www to www with .htaccess

If your website is accessible using both and, it can have a negative effect on any SEO campaigns that are currently active on your website.

In order to prevent duplicate listings on Google, you can redirect all non-www traffic to www, using the .htaccess file.

Simply fire up your favourite text editor, we recommend NotePad++, and edit the .htaccess file. Enter the following 3 lines, replacing all instances of with your actual domain name.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

That’s it, now your domain will redirect to the www version for all visitors.