.htaccess files are your best friend when it comes to Search engines. With multiple domains, .htaccess cleans up for you. Some rumors state that having multiple domains is good. This couldn't be more false.
If you register the domain name “domain-name.com”, that is what you get. The www is added but Apache or IIS through name aliasing. If you never specify in Apache that you ONLY want to use www.domain-name.com Google will spider both domain-name.com and www.domain-name.com. This will hurt your rankings because you are creating duplicate content and Google will not be able to decide which is more relevant.
There are 3 ways to get around this problem. First, if you are very tech savy you can fix this issue immediately in the apache config file (httpd.conf). Second, if you hosting provider allows it, you can fix this in .htaccess (most providers do, if not contact them), and third is a nice little PHP hack I wrote up. All of which I will show you now.
In your Apache configuration file you will have a section for virtual hosts, add this to it:
< VirtualHost domain-name.com > # Add this line Redirect 301 / http://www. domain-name.com/ < / VirtualHost>
Save the file and run
apachectl configtest
. If all is okay you should be good to go. Then
run apachectl restart
This file can be placed in any or multiple folders with different perameters set in each file. However, for this example we will place it in the Root or home directory of your website (public_html/.htaccess, htdocs/.htaccess).
In your favorite text editor All you have to enter is:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{http_host} ^domain-name\.com [nc]
RewriteRule ^(.*)$ http://www.domain-name.com/$1 [R=permanent,nc,L]
Finally if worse comes to worse and you cannot use Apache or .htaccess, I have your solution!!!! PHP to the rescue! Add this before any HTML or text is printed on your site or you will get a header error:
// redirect to one URL -- takes the place of mod rewrite in htaccess if($_SERVER['HTTP_HOST'] != 'www.main-domain.com'){ header("Location: http://www.main-domain.com".$_SERVER['REQUEST_URI'].""); }
You can also use this if you have multiple domains like domain-name.com and domainname.com. You more than likely do not want to have both sites since this could hurt you more than help you.
So for each domain you have you must enter the RewrireCond and RewriteRule. You cannot place multiple conditions to one rule (so I found out the long way).
Here is what a .htaccess looks like for 2 domains being pointed to one domain:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{http_host} ^domain-name\.com [nc]
RewriteRule ^(.*)$ http://www.domain-name.com/$1 [R=permanent,nc,L]
RewriteCond %{http_host} ^domainname\.com [nc]
RewriteRule ^(.*)$ http://www.domain-name.com/$1 [R=permanent,nc,L]
RewriteCond %{http_host} ^www\.domainname\.com [nc]
RewriteRule ^(.*)$ http://www.domain-name.com/$1 [R=permanent,nc,L]
Notice we did one for domainname.com and www.domainname.com. Also. only in the first line of each call we used the “\” to escape the ”.”. This is part of Regular Expressions, which is a language used to parse through strings and retrieve values.
That was just the first step to cleaning up your site for Search Engine Optimization, however, it is a very important step!