UK Support 01392 914033 Offices are currently closed

Creating a www. Redirect

13th May 2014 Company, Tutorials

I was asked today how to create a redirect on a website so visitors of that site who accessed it with the non www. address got redirected automatically to the www. version. The reason, in this particular case, was to improve the SEO of the website.

So, in this instance, we had the website accessible at:

And the issue with this set-up was that it was possible the content was being seen as a duplicate (because, technically – it’s two separate addresses) also, when users were sharing the content on social networks like Facebook and Google Plus the counters weren’t adding up correctly. This was because i.e 30 people had shared whereas 200 people had shared .

Setting up a non www. redirect

To solve this issue you can set-up a redirect in your .htaccess file. For our hosting customers you’d need to access your website via FTP and get the file from your “public_html” folder (the root folder). If you don’t have a .htaccess file there you can create one from scratch, just open a .txt editor and save it as .htaccess (without any file extension at the end).

Once you’ve found/created your file you just want this snippet of code there:

[pastacode lang=”markup” message=”.htaccess file” highlight=”” provider=”manual”]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

And that’s it! You’ll now get redirected to if you visited

Facebook Twitter LinkedIn Email