Javascript 如何创建重定向域?

Javascript 如何创建重定向域?,javascript,php,redirect,Javascript,Php,Redirect,这篇文章只是为了学习一些东西,最近我在facebook.com的一个页面上遇到了一个名为www.content-queen.me/PtWkz的域,点击这个链接,它将我重定向到另一个域…起初我看不到它,但下一次我用另一个url看到它时,同样的事情也发生了..所以我的问题是如何做,我知道如何创建重定向,就像在.htaccess中可以做的那样,但是这种重定向非常新而且有趣,我甚至尝试剖析代码并找到了这个源代码 <!DOCTYPE html> <html xmlns="ht

这篇文章只是为了学习一些东西,最近我在facebook.com的一个页面上遇到了一个名为www.content-queen.me/PtWkz的域,点击这个链接,它将我重定向到另一个域…起初我看不到它,但下一次我用另一个url看到它时,同样的事情也发生了..所以我的问题是如何做,我知道如何创建重定向,就像在.htaccess中可以做的那样,但是这种重定向非常新而且有趣,我甚至尝试剖析代码并找到了这个源代码

<!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

  <head>
    <meta charset="UTF-8">

    <title>When 9 Cops Sat Down At Red Robin, The Waitress Realized Something Is Terribly Wrong</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta property="og:locale" content="en_US" />
    <meta property="og:type" content="article" />
    <meta property="og:title" content="When 9 Cops Sat Down At Red Robin, The Waitress Realized Something Is Terribly Wrong" />
    <meta property="og:description" content="You never know when any deed done by you can make anyone's day. Hence, being on the good side of the threshold is always preferable. Jessica Dunbar definitely understands the effect good actions have and she is definitely doing everything the right way. Especially, when it is about men in uniform. When she notices a group of cops sitting in her section, this happens." />
    <meta property="og:url" content="http://www.content-queen.me/PtWkz" />


    <meta property="og:image" content="http://cdn.wf-media.com/18644/pvoaelaw7buvswooe47x.jpeg" />
    <meta property="og:site_name" content="www.content-queen.me" />


    <meta property="article:section" content="Pictures" />


    <a href="https://www.viral9.com/tr_hs_vs/PtWkz" id='myLink'></a>


    <style type="text/css">
      #myLink {
        display: none;
      }
    </style>

      </head>

    <body>
<div id="output">


</div>


    </body>
</html>


<script type="text/javascript">


 // view_count_update();


function view_count_update()
      { 
        var jUTM = "utm_source=SOURCE&utm_medium=referral&utm_campaign=CAMPAIGN&utm_hash=HASH";

               var redirect_url = "http://www.wittyfeed.com/story/18644/when-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong?utm_source=SOURCE&utm_medium=SOCIAL&utm_campaign=33-campaign&utm_hash=PtWkz&i=2";
               redirect_url = redirect_url.replace("SOURCE", document.referrer.split('/')[2]);
               window.location = redirect_url;    
      }


    function myFunc(){

    }



    //hello
</script>

<script>
  try{
    (function(){
      var d = {
          'user_id'       : "33",
          'url_id'        : "2609257" ,
          'advertiser_id' : "1",
          'user_agent'    : navigator.userAgent,
          'campaign_id'   : "18362" ,
      }
      $.ajax({ 
          url: "http://www.asapoo.com/mysql_testing",
          type:'GET',
          data: d,
          success : function(data) {view_count_update();},
          error   : function(){ view_count_update();},
          complete: function() {view_count_update();},
          timeout : 2000 
        });

    })();  
  }catch(e){ view_count_update(); }
</script>


<script src="//c.fqtag.com/tag/implement-r.js?org=T6tuwESp3TrUwruYu4eZ&p=NOTSET&a=33&cmp=PtWkz&rt=display&sl=1&fmt=banner&ctu=http%3A%2F%2Fwww.wittyfeed.com%2Fstory%2F18644%2Fwhen-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong%3Futm_source%3DSOURCE%26utm_medium%3DSOCIAL%26utm_campaign%3D33-campaign%26utm_hash%3DPtWkz%26i%3D2&fq=1"></script>

当9名警察坐在红罗宾酒店时,女服务员意识到事情严重不对劲
#myLink{
显示:无;
}
//查看计数更新();
函数视图\计数\更新()
{ 
var jUTM=“utm_source=source&utm_medium=reflection&utm_campaign=campaign&utm_hash=hash”;
var redirect_url=”http://www.wittyfeed.com/story/18644/when-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong?utm_source=SOURCE&utm_medium=SOCIAL&utm_campaign=33-活动&utm_hash=PtWkz&i=2”;
redirect_url=redirect_url.replace(“SOURCE”,document.referer.split('/')[2]);
window.location=重定向\u url;
}
函数myFunc(){
}
//你好
试一试{
(功能(){
变量d={
'用户id':“33”,
“url_id”:“2609257”,
'广告商id':“1”,
“用户代理”:navigator.userAgent,
“活动id”:“18362”,
}
$.ajax({
url:“http://www.asapoo.com/mysql_testing",
类型:'GET',
数据:d,
成功:函数(数据){view_count_update();},
错误:函数(){view\u count\u update();},
完成:函数(){view_count_update();},
超时:2000
});
})();  
}catch(e){view_count_update();}

我希望会有人在这里做这件事,并想学习如何做。

这段代码几乎就是它,真的。重定向来自一个专门为此设置的站点。它很可能有一个数据库驱动它,将这些随机的字母串映射到站点。然后,它有一个模板,用于您在此处发布的页面,它在其中填充数据库中的值


您可以在代码中看到它在哪里更新页面视图计数器。然后,在这之后,它将window.location设置为他们希望你去的地方,这使得浏览器加载页面。

这称为url缩短器,你需要一个后端脚本来执行重定向

应用程序的工作方式如下:当请求时,它将分析url。并将随机字符串PtWkz作为一个键,该键连接到原始url以及存储在数据库或缓存中某处的关系

脚本所做的是将短字符串与原始url匹配,并发送到浏览器http重定向302

短网址有一些特点,比如你可以通过保持共享短网址来更改目的地原始url

后端脚本可以用所有编程语言和脚本编写,您可以使用python或php

有许多在线url缩短服务,如goo.glbitly.com