301 htaccess non-www vs www

15 September 2010 in Geekery

Had a client ask about how to properly do 301 redirects for forcing www traffic to the non-www URL. That is http://fiveohtwo.com versus http://www.fiveohtwo.com.

Of course, this isn’t anything new. It’s all over the internet, but hey, one more blog post won’t clog the internet any more… right?

If you use www.yoursite.com, this part is for you.

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

The code above will 301 redirect the non-www version to the www version. Obviously replace seo-consultant-services and co.uk with your domain name/tld.

If you prefer http://fiveohtwo.com, then see below

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

So, drop one or the other into your .htaccess file, update the domain to match yours, and you’re on your way.

Tags: , , , , ,

15 September 2010 Geekery

No comments yet.

Leave a comment



Spam Protection by WP-SpamFree