A couple of my users have been giving out their domain name as "blahblah.com" instead of "www.blahblah.com". The interesting thing of course, they don’t resolve to the same place (in Linux anyway) unless you configure your system to handle things that way. Doing it with 301s is about the best way. Here is an example of how I configured this. I have several Virtual Hosts and the default one goes to this file, all by itself, as the only file in the directory.
File: index.php
<?php $get = $_GET; $serverip = 'yourserverprivateip'; $servername=$_SERVER['SERVER_NAME']; $check = explode(".",$servername); if(count($check)==4){ if($servername == $serverip){ $redirectlink = 'http://domain.tdl'; //do not edit below here header ('HTTP/1.1 301 Moved Permanently'); header('Location: '.$redirectlink); exit; } } if(($check[0]=='www') || (count($check)==3)){ ?> <html> <head> </head> <body> <p>Welcome. You are here.</p> <p>The internet.</p> <? //print '<p>Get: ' . $get . '</p>'; ?> </body> </html> <? } else { $redirectlink = 'http://www.' . $servername; //do not edit below here header ('HTTP/1.1 301 Moved Permanently'); header('Location: '.$redirectlink); exit; } ?>