« 例:createElement方法HTML颜色参考 »

利用404跳转来解决域名更换的问题

当更换域名之后,搜索引擎和其它外部来的访问可能还会指向原有的域名,下面介绍一些思路来解决这个问题。

第一:利用javascript进行404跳转

<script language="javascript">
var newdomain="www.go2map.com";                //新域名
var stoptime=2;                                //404页面停留时间,以秒为单位

var My_Url=document.location.href;
godomain();
function godomain()
{
        var str=My_Url;
        stag=str.indexOf('//')+1;
        str=str.substring(stag+1,str.length)
        stag=str.indexOf('/');
        rstr=str.substring(0,stag);
        olddomain=rstr;
        My_Url=My_Url.replace(olddomain,newdomain);
        setTimeout("gourl()",stoptime*1000);
}
function gourl()
{window.location=My_Url;}
</script>

第二:vbscript版本的

<script language="vbscript">
const newdomain = "http://im286.com"         '新域名
const stoptime = 2                        '404页面停留时间,以秒为单位

dim  My_Url
My_Url = document.location.href
My_Url = mid(My_Url,instr(8,My_Url,"/"))
document.write("<meta http-equiv='refresh' content='" & stoptime & ";url=" & newdomain & My_Url & "'>")
</script>

第三:asp文件404

<%
dim:url,newdomain
newdomain="www.2.com/"  '新玉米加上/
url=Request.ServerVariables("URL")  '取得当前路径
Response.Redirect "http://"&newdoamin&URl
Response.End()
%>

如果是同一个空间  仅仅是换米的话 如果是asp文件 可以用下面的代码废掉旧米
R.asp
<%
dim:url,newdomain
newdomain="www.2.com"  '新玉米
If Request.ServerVariables("Server_name")<>newdomain Then
      url=Request.ServerVariables("URL")  '取得当前路径
      Response.Redirect "http://"&newdoamin&"/"&URl
      Response.End()
End If
%>

原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。