这篇文章只是为了学习一些东西,最近我在facebook.com的一个页面中遇到了一个名为 www.content-queen.me/PtWkz 的域名,点击了这个链接的帖子它重新定向了另一个域 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 :(得分:0)
这个代码非常真实。重定向来自为此设置的网站。它很可能有一个驱动它的数据库,将那些随机字母串映射到站点。然后,它为您在此处发布的页面提供了一个模板,用于填充数据库中的值。
您可以在代码中看到它更新页面视图计数器。然后,在此之后,它会将window.location
设置为他们希望您去的地方,这会使浏览器加载页面。
答案 1 :(得分:0)
这称为url shortener,您需要一个后端脚本来执行重定向。
该应用程序的工作方式如下,当www.content-queen.me/PtWkz请求时,它会分析该网址。并将随机字符串 PtWkz 作为键,此键连接到原始URL,并将关系存储在数据库或缓存中的某处。
脚本的作用是将短字符串与原始网址相匹配,然后发送到浏览器http重定向302.
缩短器有一些缺点,就像您可以通过保持共享短网址来更改目标原始网址。
后端脚本可以用所有编程语言和脚本编写,你可以使用python或php。
有许多在线网址缩短服务,例如 goo.gl 和 bitly.com 。