Canonical URL format question

If I want to re-direct a www url to the non-www version, do I still add the redirect code in the .htaccess file?

And would this be the correct code?

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

Do I need to add anything else for sub-domains?

I’ve also seen reference to changing preferences in Google Webmaster Tools. Should this be done in addition to (or instead of) the htaccess?

Thank you,
Ron

@dklynn, the resident Apache mod_rewrite expert, gives this code in his tutorial, to eliminate the www

RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\\.com$ [NC]
RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

As he then goes on to give another version that preserves the www. in a subdomain, I’d guess that one doesn’t. :slight_smile:

In addition. But I think you need to do Google first. You have to verify both “sites” in Google (i.e. the www version and the non-www version) before you can pick one or the other as your preferred domain. If you set up the rewrite first, I don’t think you’ll be able to verify the www version.

Hope that makes sense. :slight_smile:

It sure helps!
And thank you for the link to the tutorial. I’ll go through it now.

Thanks again!