Forcing the www prefix with PHP/htaccess/mod_rewrite
snippet in htaccess

Forcing the www prefix with PHP/htaccess/mod_rewrite

user4677

$url= $_SERVER["SERVER_NAME"];
$page=$_SERVER["REQUEST_URI"]; 
if($url == "example.com"){
    header("Location: http://www.example.com$page");
}