Web Designer in Hastings

Coding: .htaccess


Redirect non-www to www

Search engines see http://yourdomain.com and http://www.yourdomain.com to be two different websites. As a result, if there are links to your website using a mix of the two URLs then the search engines will pick up on this and list both as seperate entries. This will have several undesirable effects as not only will there be a duplicate content issue, but the benefits of your link popularity will be diluted between the two sites. Both causing your rankings to be considerably lower than if just one site was listed.

How to fix it

Using a 301 redirect on one version of the URL will solve the problem. This is seen by search engines as a “permanent” redirect, allowing you to effectively consolidate all of your visitors to a single URL. This will also actively increase your website’s chances of obtaining and maintaining higher search engine rankings.

Should I choose www or non-www?

This very much depends on which version of your URL currently has the higher ranking with search engines and will usually coincide with which version currently has the most incoming links pointing at it.

Redirecting non-www to www

If you decide to redirect all non-www visitors to the www version of your website, all you need to do is add the following code to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirecting www to non-www

If you want to redirect all www visitors to the non-www version, add the following code to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]


Redirect www to non-www