Website Design Agency London

Redirecting a non-www website to www website with .htaccess

If Google or one of the other search engines is listing your website without the www prefix, this simple redirect will ensure that its added back in again. This will only work if you are hosting your site on an Apache web server. If this method doesn't appeal, you can edit the way your website is listed using Google's Webmaster Tools (this only changes Google's own listings though).

Simply create a new file called .htaccess in a simple text editor. Note that .htaccess is the file extension, there is no file name. Then add the following script, before uploading the file to your webserver's root directory.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]