// Remove www
if ($_SERVER['HTTP_HOST'] == 'www.example.com') {
header('HTTP/1.0 301 Moved Permanently');
header('Location: http://example.com'. $_SERVER['REQUEST_URI']);
exit();
}// Require www
if ($_SERVER['HTTP_HOST'] == 'example.com') {
header('HTTP/1.0 301 Moved Permanently');
header('Location: http://www.example.com'. $_SERVER['REQUEST_URI']);
exit();
}