redirect for www to non-www with 301
// http://stackoverflow.com/questions/2079457/www-to-non-www-redirect-with-php
// http://stackoverflow.com/questions/16497638/php-redirect-for-www-to-non-www-with-301-on-iis
if (substr($_SERVER['HTTP_HOST'], 0, 4) === 'www.') {
header("HTTP/1.1 301 Moved Permanently", true, 301);
header('Location: http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 's':'').'://' . substr($_SERVER['HTTP_HOST'], 4).$_SERVER['REQUEST_URI']);
exit;
}