Clean up URL’s with .htaccess

Many websites work with either “www.mysite.com” or “mysite.com”. Google doesn’t like that since it looks like two sites–sometimes they might penalize you for it.

From their guidelines page:

Don’t create multiple pages, subdomains, or domains with substantially duplicate content.

Here’s an excerpt from my .htaccess file that rewrites the URLs without the “www.” to include it:

# rewrite 185vfx.com to www.185vfx.com
RewriteCond %{HTTP_HOST} !^www\..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*)\.(com|co\.uk)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=permanent,L]

I grabbed this code from a discussion board somewhere a while ago but I don’t have the link handy to give credit where credit is due.