一些关于重定向的问题解答
时间:2010-09-28 来源:完美奶嘴
因为有朋友在“程序技术支持区”问到《如何整站301定向》,所以今天Winter就这个问题做一个小结,希望有不足遗漏和不足之处请朋友们指出!
动态页面进行301重定向的权重传递是最优化的,代码如下:
<!--ASP:-->
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.seowhy.com"
Response.End
%>
<!--PHP:-->
<?php
if ( $_SERVER['SERVER_NAME'] == 'seowhy.com'){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.seowhy.com");
exit();
}
?>
如果我想把 http://seowhy.com 权重转移到 http://www.seowhy.com 该怎么操作呢?
很简单,情况下面代码.
<!--ASP:-->
<%
if Request.ServerVariables("Http_Host") ="seowhy.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.seowhy.com"
Response.End
end if
%>
<!--PHP:-->
<?php
if ( $_SERVER['SERVER_NAME'] == 'seowhy.com'){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.seowhy.com");
exit();
}
?>
我想做完美的301跳转,也就是子页面跳转到对应的子页面怎么操作呢?
同级域名跳转例如:
http://www.seowhy.com/bbs/?fromuid=43913
http://www.seowhy.com/bbs/?fromuid=43913
已经有网友成功验证,这个方法是可行的.效果比动态的301跳转来的慢一些.
<%
netpath = "http://www.seowhy.com"
netpath = netpath&Request.ServerVariables("PATH_INFO")
response.write netpath
Response.Status="301 Moved Permanently"
Response.AddHeader "Location",netpath
Response.End
%>
非同级域名跳转例如:
http://seowhy.com/bbs/?fromuid=43913
http://www.seowhy.com/bbs/?fromuid=43913
也不难,如下.
<%
Dim dm,sn
dm=Request.ServerVariables("Server_name") '获取域名
'这里的3是指www的长度
if left(dm,3)<>"www" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", GetUrl()
Response.End
end if
'获取当前Url参数的函数
Function GetUrl()
Dim ScriptAddress,Servername,qs
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))
Servername = CStr(Request.ServerVariables("Server_Name"))
qs=Request.QueryString
if qs<>"" then
GetUrl ="http://www."& Servername & ScriptAddress &"?"&qs
else
GetUrl ="http://www."& Servername & ScriptAddress
end if
End Function
%>
在我们遇到了静态页面的时候如何做权重转移呢?
很多时候因为网站改版或者什么其他原因,有些静态页面已经有很高的PR了,如何把这些高PR的静态页面转移到其他网页上呢.
需要对一些静态页面进行转移,一个网页能否算是成功读取,服务器会给客户端返回一个成功读取的参数,一般是200错误.说到这里可能有些朋友会有点晕,为什么是错误呢,这里指的200错误是指服务器返回值,例如:当打开某网页,网页不存在时会返回404错误,权限不足时会返回401错误等等.
这里做的静态页面权重转移就是要利用404错误.
建一个error.asp文件.指定404错误跳转到error.asp文件.
然后error.asp文件分析网址,得到旧网址,再通过上面的301代码跳转到新的网址.
还有一种方法就简单点.直接用元描述跳转
[CODE_LITE] </p>
<meta http-equiv=”refresh” content=”10;URL=http://www.seowhy.com”>
动态页面进行301重定向的权重传递是最优化的,代码如下:
<!--ASP:-->
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.seowhy.com"
Response.End
%>
<!--PHP:-->
<?php
if ( $_SERVER['SERVER_NAME'] == 'seowhy.com'){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.seowhy.com");
exit();
}
?>
如果我想把 http://seowhy.com 权重转移到 http://www.seowhy.com 该怎么操作呢?
很简单,情况下面代码.
<!--ASP:-->
<%
if Request.ServerVariables("Http_Host") ="seowhy.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.seowhy.com"
Response.End
end if
%>
<!--PHP:-->
<?php
if ( $_SERVER['SERVER_NAME'] == 'seowhy.com'){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.seowhy.com");
exit();
}
?>
我想做完美的301跳转,也就是子页面跳转到对应的子页面怎么操作呢?
同级域名跳转例如:
http://www.seowhy.com/bbs/?fromuid=43913
http://www.seowhy.com/bbs/?fromuid=43913
已经有网友成功验证,这个方法是可行的.效果比动态的301跳转来的慢一些.
<%
netpath = "http://www.seowhy.com"
netpath = netpath&Request.ServerVariables("PATH_INFO")
response.write netpath
Response.Status="301 Moved Permanently"
Response.AddHeader "Location",netpath
Response.End
%>
非同级域名跳转例如:
http://seowhy.com/bbs/?fromuid=43913
http://www.seowhy.com/bbs/?fromuid=43913
也不难,如下.
<%
Dim dm,sn
dm=Request.ServerVariables("Server_name") '获取域名
'这里的3是指www的长度
if left(dm,3)<>"www" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", GetUrl()
Response.End
end if
'获取当前Url参数的函数
Function GetUrl()
Dim ScriptAddress,Servername,qs
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))
Servername = CStr(Request.ServerVariables("Server_Name"))
qs=Request.QueryString
if qs<>"" then
GetUrl ="http://www."& Servername & ScriptAddress &"?"&qs
else
GetUrl ="http://www."& Servername & ScriptAddress
end if
End Function
%>
在我们遇到了静态页面的时候如何做权重转移呢?
很多时候因为网站改版或者什么其他原因,有些静态页面已经有很高的PR了,如何把这些高PR的静态页面转移到其他网页上呢.
需要对一些静态页面进行转移,一个网页能否算是成功读取,服务器会给客户端返回一个成功读取的参数,一般是200错误.说到这里可能有些朋友会有点晕,为什么是错误呢,这里指的200错误是指服务器返回值,例如:当打开某网页,网页不存在时会返回404错误,权限不足时会返回401错误等等.
这里做的静态页面权重转移就是要利用404错误.
建一个error.asp文件.指定404错误跳转到error.asp文件.
然后error.asp文件分析网址,得到旧网址,再通过上面的301代码跳转到新的网址.
还有一种方法就简单点.直接用元描述跳转
[CODE_LITE] </p>
<meta http-equiv=”refresh” content=”10;URL=http://www.seowhy.com”>
相关阅读 更多 +