帶www與不帶www的域名,在域名解析和網(wǎng)站管理上都可以是獨(dú)立的,但是除非特別的原因,否則絕大多數(shù)網(wǎng)站帶www與不帶www的域名都是指向同一個(gè)站點(diǎn),網(wǎng)站內(nèi)容是不分開的,然而盡管如此,搜索引擎仍然會(huì)認(rèn)為帶www與不帶www的域名是代表兩個(gè)不同的網(wǎng)站,在收錄和權(quán)重分配上仍然是分開的。這就是所謂的“權(quán)重分散”,對于網(wǎng)站SEO優(yōu)化來說,是一個(gè)需要特別重視的部分。本文將要介紹幾種方法,避免帶www與不帶www域名的權(quán)重分散。
IIS重定向(web.config)配置:
方法1: <rewrite> <rules> <rule name="Non-WWW only" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions> <add input="{HTTP_HOST}" pattern="^(.*)wan-qi.cn$" ignoreCase="false" negate="true" /> <add input="{HTTP_HOST}" pattern="^localhost$" ignoreCase="false" negate="true" /> <add input="{HTTP_HOST}" pattern="^www\." ignoreCase="false" negate="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="http://www.{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> 方法2: <rewrite> <rules> <rule name="Host Name" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^(.*)wan-qi.cn$" /> </conditions> <action type="None" /> </rule> <rule name="Non-WWW only" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions> <add input="{HTTP_HOST}" pattern="^www." ignoreCase="false" negate="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="http://www.{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite>
ASP代碼:
<% Servername=CStr(Request.ServerVariables("Server_Name")) if Servername="localhost" or Instr(Servername,"wqhl.cn")>0 then else strurl=Replace(weburl,"http://","") strurl=Replace(strurl,"/","") If strurl<>Servername Then ScriptAddress=CStr(Request.ServerVariables("SCRIPT_NAME")) qs=Request.QueryString if qs<>"" then Url ="http://"&strurl&ScriptAddress &"?"&qs else Url ="http://"&strurl&ScriptAddress end if Response.Status="301 Moved Permanently" Response.AddHeader "Location", Url Response.End end If end If %>
PHP代碼:
<?php $the_host = $_SERVER['HTTP_HOST'];//取得當(dāng)前域名 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判斷地址后面是否有參數(shù) if($the_host == 'webkaka.com')//把這里的域名換上你想要的 { header('HTTP/1.1 301 Moved Permanently');//發(fā)出301頭部 header('Location: http://m.fjgmzy.com'.$request_uri);//跳轉(zhuǎn)到你希望的地址格式 } ?>
建站咨詢熱線
029-33273980