FreeBSD Server Administration

« Beastie Blog | Main | 301 Redirect »

January 13, 2006

Apache and Google

This post is more about Google, but I think it's very important and I should mention it.

Let me use this blog as an example to explain the problem. This blog can be accessed by typing freebsdblog.org or www.freebsdblog.org in your browser, there is no any difference to you. But Google treats them as two different websites, since they have exactly the same content, Google may dump out one of them due to duplicated content penalty. If Google bans the one you have been promoting, that would be a big problem.

This may sound very silly, but it has been discussed for years and reported by many webmasters. Recently, my sites also had some problems like this, although I'm not very sure about the reasons. If you try Yahoo, Google, MSN or FreeBSD, all of the big guys redirect you to the www version with permanent redirection (HTTP 301). Anyway, I strongly suggest you configure your domains this way, by which you will only benefit from it:

1. Avoid the possible duplicated content penalty. In case it happens, it is vital.

2. All your back links will help your search engine ranking whether they point to www or non-www version.

Solution
This can be configured with .htaccess or httpd.conf.

.htaccess
Make a file name ".htaccess" with the following content and put it in the DocumentRoot directory. If there are other .htaccess in any sub-directories, they should be modified too:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^freebsdblog.org
RewriteRule (.*) http://www.freebsdblog.org/$1 [R=301,L]

httpd.conf
If you have access to the main Apache configuration file, you can configure it in the domain level, which is a much more elegant solution:

<VirtualHost 72.21.48.122>
ServerAlias freebsdblog.org
ServerAdmin your_email_address
DocumentRoot /home/freebsd/www
ServerName www.freebsdblog.org
RewriteEngine On
RewriteCond %{HTTP_HOST} !^72.21.48.122(:80)?$
RewriteCond %{HTTP_HOST} !^www.freebsdblog.org(:80)?$
RewriteRule ^/(.*) http://www.freebsdblog.org/$1 [L,R=301]

ErrorLog /var/log/www/freebsdblog.org-error_log
CustomLog /var/log/www/freebsdblog.org-access_log combined
</VirtualHost>


Category : Apache

Posted by FreeBSD Newbie at January 13, 2006 05:36 PM

Comments

Hi,

I am not sure, but shouldn't it have been this for httpd.conf


ServerAlias freebsdblog.org
ServerAdmin your_email_address
DocumentRoot /home/freebsd/www
ServerName www.freebsdblog.org
RewriteEngine On
RewriteCond %{HTTP_HOST} !^72.21.48.122(:80)?$
RewriteCond %{HTTP_HOST} !^freebsdblog.org(:80)?$
RewriteRule ^/(.*) http://www.freebsdblog.org/$1 [L,R=301]
ErrorLog /var/log/www/freebsdblog.org-error_log
CustomLog /var/log/www/freebsdblog.org-access_log combined

Posted by at April 28, 2006 07:31 PM

Post a comment



(Optional, will not be shown to the public)

Remember Me?