301 Redirect from non-www to ww -- Without Looping!

So - you want to improve your search engine rankings, and SEO experts are telling you that Google may be penalizing you for having links to your site using www in some cases and no www in others, as the spider may see it as duplicate content.  And so they've recommend you create a 301 redirect to send all non-www links to www.  You try it, and to your horror, the page now loops through so many redirect iterations that the site won't display at all.  Or, you try the common syntax and it messes up all your subdomains.

Well, there's hope.  Here's a 301 redirect syntax that does not loop, and does not affect your subdomains.

If you're new to 301 redirects, the first thing you want to do is create or edit an existing .htaccess file, which should be in your public_html or web root folder.  Add the following lines, substituting your actual domain name instead of the 'yourdomain' and 'com' we list here (So, change out the green text)

 This one will take you from non-www to www:

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

  • 4 Users Found This Useful
Was this answer helpful?

Related Articles

301 Redirect for All Domains

So you've purchased a ton of domains to park on your main account, but you don't want Google to...

Block a country using mod_geoip

Do you have a list of countries that you want to block access to your site?  Have you tried...

Hotlink protecting image.php and GD images

So you've enabled cpanel's hotlink protection, but those bandwidth theives are still attacking...

How do I redirect a page or folder?

I have removed a file from being on the website and would like to forward people who were looking...

How to block an IP number

A user is accessing our website and we'd like to block this user as they continue to submit...