« tabs vs spaces | self induced complications »
April 29, 2009 12:08 a.m.
I learned something recently about SEO that I didn't realize in the past. Yes, I know some of the SEO guys out there will go, "DUH!" Although, until I actually saw it in action, I truly didn't realize the impact.
To make things simple, I will be using domain.com as my example domain throughout the explanation. Typically (I did say typically and not always), your DNS servers should be pointing domain.com and www.domain.com to the same IP address. Plus, your web server should also be listening for both domain.com and www.domain.com.
In the past, I've usually set this up under the same VirtualHost directive in Apache, while using www.domain.com for the ServerName and domain.com for the ServerAlias (and any other aliases that may pertain).
Well, recently I've come to realize that some search engines view www.domain.com and domain.com as two totally different domains. Even though they're in the same VirtualHost and serve up the exact same content. So, your stats are split depending on the actual address that was requested. This will skew your stats quite a bit unless you are combining both domain addresses into one report.
Now that I've sat down and thought about it, the search engine logic makes perfect sense. How are they to know if www.domain.com and domain.com are meant to be in the same place. So they treat them as independent domains, because they are truly independent names and could potentially live in different places.
So, to resolve this problem, I've decided to take domain.com out of the ServerAlias directive and create it's own VirtualHost. That will permanently redirect to the www.domain.com URL that matches.Including sub directories and filenames.
This can easily be done by editing your httpd.conf file and moving domain.com from ServerAlias and adding an additional VirtualHost that looks similar to this:
<VirtualHost your_server_ip:80>
ServerName domain.com
RedirectMatch 301 (.*)$ http://www.domain.com$1
</VirtualHost>
And there ya go... Anything going to domain.com, including sub directories and sub pages will be redirected permanently to www.domain.com with the same sub directories and/or sub pages.
It will take some time, but most search engines will see these permanent redirects and index them properly the next time around.