开发者

Forcing the www prefix with PHP/htaccess/mod_rewrite

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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜