域名跳转代码

欢迎来到米粒在线,今天看到一个问题:

我们在浏览器 输入 3.cn 转入京东的网站,但网址是http://www.jd.com/?utm_source=3.cn这样的形式的,

我对这个不了解,所以想学习下,问了群友,问了一些IDC客服,最后在谷歌搜到一篇新浪博客的文章。特此记录下来给大家参考学习,原文如下:


方法一:asp

<%
if Request.ServerVariables("SERVER_NAME")="www.xxx.com" then
response.redirect "http://www.xxx.com/user/"
elseif Request.ServerVariables("SERVER_NAME")="xxx.com" then
response.redirect "http://www.xxx2.com/user2/"
else
response.redirect "http://www.***.net/"
end if
%>

asp版的还有人这么写:
<%if Request.ServerVariables(SERVER_NAME)=www.0552.biz then
response.redirect http://www.0552.biz/bb0552/
else%>
<%end if%>
<%if Request.ServerVariables(SERVER_NAME)=www.bb0552.com then
response.redirect bb0552/
else%>
<%end if%>
<%if Request.ServerVariables(SERVER_NAME)=bbjyc.com then
response.redirect bbjyc/
else%>
<%end if%>

方法二,htm都可以搞定,这个比较简单
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<BODY>
<Meta name="Keywords" Content="xxxxxxxxxxxxxxxxxxxxxxxxx,xxxxxxxxxxxx,xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxxx,xxxxxxxxxxx">
<Meta name="Description" Content="xxx,xxxxx,xxxx,xxxx">
<Meta name="Robots" Content="All">
<script language="JavaScript">
if(location.hostname=="www.bb0552.com")
location="/bb0552";
if(location.hostname=="www.0552.biz")
location="/bb0552";
if(location.hostname=="bb0552.com")
location="/bb0552";
if(location.hostname=="www.bbjyc.com")
location="/bbjyc";
if(location.hostname=="www.bbjyc.cn")
location="/bbjyc";
if(location.hostname=="jyclc.cn")
location="/bbjyc";
if(location.hostname=="www.txtebook.com")
location="/txtebook";
if(location.hostname=="fc.bb0552.com")
location="/fc";
if(location.hostname=="bb0552.com")
location="/bb0552";
if(location.hostname=="0552.biz")
location="/bb0552";
if(location.hostname=="bbjyc.com")
location="/bbjyc";
if(location.hostname=="fc.0552.biz")
location="/fc";
if(location.hostname=="dhzd.bbjyc.cn")
location="/bbjyc";
if(location.hostname=="jyclc.bbjyc.cn")
location="/bbjyc";
if(location.hostname=="www.8you.com")
location="/bb0552";
if(location.hostname=="bbs.0552.biz")
location="/bbs";
if(location.hostname=="bbs.bb0552.com")
location="/bb0552";
if(location.hostname=="")
location="/bb0552";
</script>
</BODY>
</HTML>

php的代码:
<?php
switch ($_SERVER["HTTP_HOST"])
{
case "www.bb0552.com":
header("location:/bb0552");
break;
case "www.bbjyc.com":
header("location:/bbjyc");
break;
case "www.txtebook.com":
header("location:/txtebook");
break;
case "fc.bb0552.com":
header("location:/fc");
break;
case "bb0552.com":
header("location:/bb0552");
break;
case "bbjyc.com":
header("location:/bbjyc");
break;
case "bbjyc.cn":
header("location:/bbjyc");
break;
case "www.bbjyc.cn":
header("location:/bbjyc");
break;
case "dhzd.bbjyc.com":
header("location:/bbjyc");
break;
case "www.0552.biz":
header("location:/bb0552");
break;
case "0552.biz":
header("location:/bb552");
break;
case "":
header("location:/bb552");
break;
}
?>

js跳转。(这样好象只针对废弃的站,然后这样跳转到新站)
JS跳转到另外一个米,这样百度蜘蛛依然爬我原来的米,而访客一访问就跳到新米了.

程序代码
try
{
var s_domain = location.host;
var js_path = "不带http新米";
if (s_domain != js_path)
{
var str=window.location.href;
var es=/老米不带www/;
es.exec(str);
var right=RegExp.rightContext;
top.location.href = "http://"+js_path+right;
}
}
catch(e) { }

只跳到首页就用不着这个代码了,呵呵.
访问内容页的时候这个代码会自动访问新米内容页.
下面百度到的一些好代码.收藏.
引用内容
js提取url参数的几种方法。
第一,正则表达式,直接找出参数等号右边的值即可。但是,如果该参数后还有&就不可行。
程序代码
<script language="javascript">
var str=window.location.href;
var es=/clid=/;
es.exec(str);
var right=RegExp.rightContext;
if(right=="1")
{
sub_nav_4.style.display = "block";
li4.style.background = "#a1ca00";
}
</script>
第二,把能找到的参数都付给argsarr数组,将来可以用argsarr[i]进行相应的访问,方法不错,太长,参数不容易记忆。
程序代码

function getArgs()
{
//加上substring的意义是去掉查询字符串中的?号。
//var query = window.location.search.substring(1);

//定义一个数组,用于存放取出来的字符串参数。
var argsArr = new Object();

//获取URL中的查询字符串参数
var query = window.location.search;
query = query.substring(1);

//这里的pairs是一个字符串数组
var pairs = query.split("&");//name=myname&password=1234&sex=male&address=nanjing

for(var i=0;i<pairs.length;i++)
{
var sign = pairs[i].indexOf("=");
//如果没有找到=号,那么就跳过,跳到下一个字符串(下一个循环)。
if(sign == -1)
{
continue;
}

var aKey = pairs[i].substring(0,sign);
var aValue = pairs[i].substring(sign+1);

argsArr[aKey] = aValue;
}

return argsArr;
}

第三,最简单的方法,类似第二种,不过没有创建数组存参数,可直接访问参数的名字,容易看懂。
程序代码
<script language="javascript">
function getarg()
{
var url = unescape(window.location.href);
var allargs = url.split("?")[1];
var args = allargs.split("&");
for(var i=0; i<args.length; i++)
{
var arg = args[i].split("=");
eval_r('this.'+arg[0]+'="'+arg[1]+'";');
}
}
var urlarg=new getarg();
if(urlarg.clid=="1")
{
sub_nav_6.style.display = "block";
li6.style.background = "#a1ca00";
}
</script>

js获取URL地址某个参数数据
程序代码
function closeThis()
{
var paraName = URL_Request("UploadPanelName");
var cm=window.parent.document.getElementByIdx(paraName);
if (cm.style.visibility=="visible")
{
cm.style.visibility = "hidden";
}
}

function URL_Request(strName)
{
var strHref = document.location.toString();
var intPos = strHref.indexOf("?");
var strRight = strHref.substr(intPos + 1);//==========获取到右边的参数部分
var arrTmp = strRight.split("&");//=============以&分割成数组
for(var i = 0; i < arrTmp.length-1; i++ ) //===========循环数组
{
var dIntPos = arrTmp[i].indexOf("=");
var paraName= arrTmp[i].substr(0,dIntPos);
var paraData= arrTmp[i].substr(dIntPos+1);

if(paraName.toUpperCase() == strName.toUpperCase())
{
return paraData;
}
}
return "";
}
</script>
用js获取当前url地址中的域名
[codevar getHost = function(url) {
var host = "null";
if(typeof url == "undefined"
|| null == url)
url = window.location.href;
var regex = /.*\:\/\/([^\/]*).*/;
var match = url.match(regex);
if(typeof match != "undefined"
&& null != match)
host = match[1];
return host;
}
alert(getHost());
alert(getHost('https://test.com'));
alert(getHost('http://test.com/123.html'));][/code]

利用JS取得地址栏参数
程序代码
假设URL的地址是 http://localhost/test.html?player=shamohai
<script>
var add = top.location;//取得地址栏的URL
add = add.toString();
var showIndex = add.indexOf("?player=");//得到参数的位置
var showParam="";//需要得到的参数
if (playerIndex != -1) {
showParam= unescape(add.substring(playerIndex + 8, add.length));

}
</script>

用JS取得页面的参数
程序代码
function QueryString(para)
{
var retval="",s=location.search.replace("?","");
if(s=="")return "";s = s.split("&");
for(var i=0;i<s.length;i++)
if(s[i].toUpperCase().indexOf(para.toUpperCase() + "=")==0)
retval+=((retval==""?"":", ")+s[i].substr(s[i].indexOf("=")+1,s[i].length));
return retval;
}

米粒在线
  • 本文由 发表于 2013年4月16日18:01:17
  • 转载请务必保留本文链接:https://www.miliol.org/7092.html
SEO相关

PHP默认时区无效最简单的解决方法

参考了网上很多方法,有的修改模板的配置文件,有的要修改PHP里面的时区,有的要修改WORDPRESS的配置文件,试了试都没有解决。 后台直接修改 首先,后台-设置-常规,检查一下WordP...
生活道理

熬夜如何改变了我们的身体

熬夜的危害有很多,如:经常感到疲劳,免疫力下降:人经常熬夜造成的后遗症,最严重的就是疲劳、精神不振;人体的免疫力也会跟着下降,感冒、胃肠感染、过敏等等自律神经失调症状都会出现。 头痛:熬夜的隔天,上班...
生活道理

马云惊人言论 引爆金融圈

近日,中国金融四十人论坛(CF40)联合各组委会成员机构在上海召开第二届外滩金融峰会。 马云出席峰会并发表言论,讲演全程金句频出、观点犀利、针砭时弊,在金融圈刷屏。他指出: 1、不必刻意填...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: