redirecting all possible hostnames to one using mod_rewrite

SEO experts claim that having multiple hostnames point to the same site will result in lower rankings for that site. It's common to see sites accept both "www.foo.com" and "foo.com".

I have no idea if this is true, but it makes a bit of sense, so why take the chance.

I want to direct everyone to "devbee.com" regardless of what they type in, with one exception. I want to allow for a hostname test.devbee.com for my own devious purposes. This is what I'd put in the mod_rewrite section of my .htaccess or httpd.conf file:

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

This tells Apache that if the hostname is not "devbee.com" *and* it is not "test.devbee.com" then make it devbee.com.

For detailed info on Apache mod_rewrite, read the official documentation .  

That was easy.

 

The 301 redirect is very useful. It actually increase the site's pagerank.