短网址如何运作?
Possible Duplicate:
How do short URLs services work?
Hi,
Can anybody explain how short URL's (technically) work, and for how long are they valid? Any articles about how does it work are welcome too (but please no example provider sites).
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
短 URL 服务器有一个数据库,将短 URL(或者更确切地说,URL 的编码部分)与其表示的实际 URL 相匹配。
当它收到请求时,它会查找编码部分并将重定向发送到实际的 URL。
因此,例如,URL http://tinyurl.com/so-hints
so-hints
匹配的完整 URLThe short URL server has a database matching the short URL (or, rather the coded part of the URL) to the actual URL it represents.
When it gets a request, it looks up the coded part and sends a redirect to the actual URL.
So, for example, the URL http://tinyurl.com/so-hints
so-hints
短网址通常使用数字和小写字母和大写字母的组合。路径组件的该集合中的六个元素(26 + 10 项)的组合已经可以提供 2,176,782,336 个唯一 ID。
如果您想研究一些源代码,本文重点介绍了 7 个开源脚本:
Short URLs usually use a combination of numbers and lowercase and uppercase letters. A combination of exactly six elements of this set (26 + 10 items) for the path component can already provide 2,176,782,336 unique ids.
If you want to study some source code, this article highlights 7 open source scripts:
只有一个关系数据库,其中有一个表,该表将短的高熵字符串映射到给定的 URL。每次有人请求时都会创建短字符串。它们不是任何形式的加密,只是查找。
There's just a relational database with a table that maps from a short, high-entropy string to a given URL. The short strings are created each time someone asks for one. They're not any form of encryption, it's just lookup.
在最简单的形式中,它只是一个与 URL 匹配的键。从那里您可以添加功能。
查看 Google 缩短程序的规范,因为它们具有相当平衡的功能集: http://code.google.com/apis/urlshortener/v1/getting_started.html
In its simplest form it is just a key that is matched to a URL. From there you can add functionality.
Have a look at the spec for the Google shortener as they have a pretty balanced feature set: http://code.google.com/apis/urlshortener/v1/getting_started.html
它们管理一系列从短到长的 URL,并将每个对短 URL 的请求重定向到其原始请求
They manage a list of short to long URLs and redirect each request to short URL to its original one