短网址服务如何运作? [英] How do short URLs services work?

查看:31
本文介绍了短网址服务如何运作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TinyURLMetamark 有用吗?
他们是否只是将微小的 URL 键与 [virtual?] 网页相关联,该网页仅提供到原始 URL 的HTTP 重定向"?还是有更多的魔法"?

How do services like TinyURL or Metamark work?
Do they simply associate the tiny URL key with a [virtual?] web page which merely provide an "HTTP redirect" to the original URL? or is there more "magic" to it ?

【原文措辞】我经常使用诸如 TinyURL、Metamark 等 URL 缩短服务,但每次使用时,我都想知道这些服务是如何工作的.他们是否创建了一个将重定向到另一个页面的新文件,或者他们是否使用子域?

[original wording] I often use URL shortening services like TinyURL, Metamark, and others, but every time I do, I wonder how these services work. Do they create a new file that will redirect to another page or do they use subdomains?

推荐答案

不,他们不使用文件.当您单击这样的链接时,会向其服务器发送一个带有完整 URL 的 HTTP 请求,例如 http://bit.ly/duSk8wK(此问题的链接).他们读取路径部分(此处为 duSk8wK),该部分映射到他们的数据库.在数据库中,他们会找到描述(有时)、您的姓名(有时)和真实 URL.然后他们发出重定向,即 HTTP 302 响应和标头中的目标 URL.

No, they don't use files. When you click on a link like that, an HTTP request is send to their server with the full URL, like http://bit.ly/duSk8wK (links to this question). They read the path part (here duSk8wK), which maps to their database. In the database, they find a description (sometimes), your name (sometimes) and the real URL. Then they issue a redirect, which is a HTTP 302 response and the target URL in the header.

这种直接重定向很重要.如果您要使用文件或首先加载 HTML 然后重定向,浏览器会将 TinyUrl 添加到历史记录中,这不是您想要的.此外,重定向到的站点会将引用者(您最初来自的站点)视为 TinyUrl 链接所在的站点(即 twitter.com,您自己的站点,无论链接在哪里).这同样重要,以便网站所有者可以看到人们来自哪里.如果页面被加载重定向,这也是行不通的.

This direct redirect is important. If you were to use files or first load HTML and then redirect, the browser would add TinyUrl to the history, which is not what you want. Also, the site that is redirected to will see the referrer (the site that you originally come from) as being the site the TinyUrl link is on (i.e., twitter.com, your own site, wherever the link is). This is just as important, so that site owners can see where people are coming from. This too, would not work if a page gets loaded that redirects.

PS:有更多类型的重定向.HTTP 301 表示:重定向永久.如果发生这种情况,浏览器将不再请求 bit.ly 或 TinyUrl 站点,并且这些站点想要计算点击次数.这就是使用 HTTP 302 的原因,这是一个临时重定向.浏览器每次都会再次询问 TinyUrl.com 或 bit.ly,这样就可以为您计算点击次数(一些小型网址服务提供此功能).

PS: there are more types of redirect. HTTP 301 means: redirect permanent. If that would happen, the browser will not request the bit.ly or TinyUrl site anymore and those sites want to count the hits. That's why HTTP 302 is used, which is a temporary redirect. The browser will ask TinyUrl.com or bit.ly each time again, which makes it possible to count the hits for you (some tiny url services offer this).

这篇关于短网址服务如何运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆