views:

31

answers:

1

How are the following different? Ignore the domain names.

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


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

The difference is "^"?

What I basically want to do is have my site as http://yourdomain.com and never have the www appear. For a start its shorter and its good for SEO as my site won't be judged as two sites. One with www and one without.

Thanks all

+1  A: 

No, they are not the same.

The first says, redirect to the host example.com if the host is www.example.com.
The second says, redirect to www.example.com if the host is not www.example.com.

And even if you would rewrite the second to the following (having both rules redirecting to example.com:

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

So that it would redirect to example.com if the host is not example.com. The result might be the same if the host can only be www.example.com and example.com. But if it can have more values than that (e.g. foobar.example.com), the your first rule would not redirect while my would redirect.

Gumbo