Redirecting non-www to www

Search engines think of http://yourweb.com and http://www.yourweb.com as completely different domains, meaning that you are potentially splitting the value of your website content by keeping them separate. Fortunately there’s an easy fix by using a 301 redirect.

What is a 301 redirect?

Put simply, a 301 redirect tells a search engine that one page has been permanently moved to another location. A 301 can be used in a variety of cases but this example will point all non-www traffic to www.

Creating the 301 redirect

1. Ensure that your server has the Apache Rewrite Module activated (If you’re unsure, contact your web hosting provider).

2. FTP into your site, download the .htaccess file from the root folder of your site, and make a backup (just in case things go wrong!)

3. Add the code below to the .htaccess file, save it, and upload to your site (remember to change yourweb.com to whatever your site is):

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

4. Lauch your web browser and go to http://yourweb.com. If you’re redirected to http://www.yourweb.com/ everything’s fine. Check your site over to make sure that no pages are broken and that’s it – done.

If there’s anything broken or your site won’t load, restore the .htaccess file that you backed up earlier and upload it to your site. There’s plenty that could go wrong so if you’re unsure I’d definitely advise getting in touch with your hosting provider to see if they’ll help.

Matt Beswick

Co-founder of Aira and Blush. Marketing / tech geek. Husband. Dad of two. Enjoyer of bourbon, cookery, computer games, and things that go fast.

Top