So, I am pretty new to .htaccess files. I think I've thought through this correctly, but I need some help verifying if I've got it right.
So, previously in my experience as an SEO, I've heard that you should NOT map two DNS records to the same server space, as Google will see that as two independent sites that each have duplicate content. If you have bought two domain names, you should set up two different hosting environments, one which has all of your website's files on it, and one which has only a .htaccess file to 301 that domain to your real domain, as opposed to just setting up one hosting environment and pointing both domain names at it. That way you have your "main" URL, and Google sees that the "sub" URL is not a duplicate site, but just redirects to the "main" URL.
However, I was talking with someone who was arguing that you COULD map two DNS records to the same server space, as long as you put in a rule in your .htaccess file along the lines of
RewriteCond %{HTTP_HOST} example2\.com
RewriteRule (.*) /$1 [R=301, L]
In this case, you have two URLS (example.com and example2.com). You want your main domain name to be example.com, so you point the DNS records for both URLS at the same hosting environment, and you use the above .htaccess rule to make it so that any time a request comes in for example2.com, it redirects it to the corresponding page on example.com instead, thus making it so Google sees your site as 1 site instead of 2.
Does this make sense? Am I on the right track? Would the above code work as described? I want to make sure I get this right before I attempt it on any client sites . . .