// force www if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.'){ // rewrite path, or request uri? $path = isset($_SERVER['HTTP_X_REWRITE_URL']) ? $_SERVER['HTTP_X_REWRITE_URL'] : $_SERVER['REQUEST_URI']; // redirect header('HTTP/1.1 301 Moved Permanently'); header('Location: https://www.'.$_SERVER['HTTP_HOST'].$path); exit(); } ?>