If you're new here and like what you read, please subscribe to my blog feed or sign up for free email updates. Thanks for visiting!
Enter your email address to subscribe:

At the top of all your PHP files (but for most CMS, this would need only be the index.php file), add this:

if (preg_match('/www\.'.$_SERVER['HTTP_HOST'].'/i', $_SERVER['HTTP_VIA']))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}


(Change to !preg_match if you want to redirect domain.com to www.domain.com)

This post has no comment. Add your own!