I can't find a definitive answer by searching here, and I hope it's not the 800th time it's been asked, but I'm trying to wrap my brain around all of this so I don't keep asking stupid questions. I also refer to
this Webmaster World post [webmasterworld.com] for basic help.
I have the following in my htaccess to redirect IP address and non www to www.
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
1. Is it really necessary to use (www\.example\.com)? and wouldn't www\.example\.com suffice? I've seen it both ways but I'd like a pros answer. I understand the ()? means match 0 or 1 time, or at least I think I understand that's what that means.
2. Is it really necessary to use ^(.*)$ instead of just (.*) ? I've seen it both ways also, is one more explicit than the other? I just don't understand how the anchors would make it any more so.
I like to keep my code as short and efficient as possible, but I also don't want to leave out a few extra characters that might make a difference in efficiency or worse yet, functionality.
Thanks!