Most of you probably know that if somebody publish a link to your original domain without 'www', it will be probably displayed anyway. However it brings headache in the terms of SEO, since it could give you a "duplicated content" penalties from search crawler like Google.
(Despite I would disagree with this opinion...)I have studied a lot of web pages regarding this subject, but most of them offer just a redirection using Apache's .htaccess. The code offered looks like:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]Unfortunatelly I am not Apache guru and can not extend this code so it works
correctly for all cases. What kind of cases? If you simply enter http://example.com/ it will work for you redirecting to http://www.example.com/. However if you enter http://example.com/somepage
.html it will not redirect to that page properly (with 'www').
Here is the simple PHP code I've programmed to put on all miniBB pages. If you are using miniBB forums, you could use it at least for your forum script, forcing redirection of any kind of forum page which is accessed without 'www', to the original domain with 'www':
$site_url='http://www.minibb.com';
if(substr($_SERVER['HTTP_HOST'], 0, 4)!='www.' and substr($_SERVER['HTTP_HOST'], 0, 9)!='localhost') {
header("HTTP/1.1 301 Moved Permanently");
header("Location:{$site_url}{$_SERVER['REQUEST_URI']}");
exit;
}
This code needs to be pasted anywhere in setup_options.php.
Feel free to apply it for any other of your web site pages as well.
Don't forget to change $site_url value of course ;-)
Check how it works:
http://minibb.com/features.html
http://minibb.com/forums/9_0.html