2016-04-24 30 views
-1

這篇文章只是爲了學習一些東西,最近我遇到了一個域名爲www.content-queen.me/PtWkz在facebook.com的一個頁面中,點擊這個鏈接後,它將我重定向到另一個域http://www.wittyfeed.com/story/18644/when-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong?utm_source=undefined&utm_medium=SOCIAL&utm_campaign=33-campaign&utm_hash=PtWkz&i=2 ...最初我看到它,但下一次我做了另一個網址,同樣的事情發生..所以我的問題是如何做到這一點,我知道如何創建一個重定向,因爲它可以完成。 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> 

我希望會有球員誰還會在這裏做這個,想學習如何去做。

回答

0

這段代碼實際上是非常多的。重定向來自爲此設置的站點。它很可能有一個數據庫驅動它,將這些隨機字母串映射到網站。然後它爲您在此發佈的頁面提供了一個模板,用於填充數據庫中的值。

您可以在代碼中看到更新頁面查看計數器的位置。然後,在此之後,它將window.location設置爲他們希望您去的地方,這會使瀏覽器加載頁面。

0

這叫做url縮短器,你需要一個後端腳本來做重定向。

該應用程序的工作原理如下,當www.content-queen.me/PtWkz的請求時,它會分析網址。並以隨機字符串PtWkz作爲關鍵字,此關鍵字連接到原始URL並將關係存儲在數據庫或高速緩存中的某處。

腳本做的是短字符串匹配到原單網址和發送到我們的瀏覽器HTTP重定向302

有一些羽毛的縮短服務一樣可以更改目的地網址繼續分享短網址。

後端腳本可以用所有編程語言和腳本編寫,您可以使用python或php。

有很多在線網址縮短服務,如goo.glbitly.com