Is there an easy way (preferably with htaccess and开发者_如何学C mod_rewrite) to force the browser to always access a site with the www. prefix (adding it automatically where necessary?)
Thx.
Rewritecond %{HTTP_HOST} !www.domain.com
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301]
or maybe
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
This is what I use:
$url= $_SERVER["SERVER_NAME"];
$page=$_SERVER["REQUEST_URI"];
if($url == "example.com"){
header("Location: http://www.example.com$page");
}
精彩评论