问题描述
我一直想知道网址多么渺小的工作。
I have been wondering how tiny url works.
我想开发我的网站类似的东西,但由于大多数人来说,我使用的GUID的标识。当创建一个对象,我应该然后生成一个10个字符的随机字符串作为公共标识的使用,或者是有一个更聪明的方法呢?
I would like to develop something similar for my site, but as most people, I use GUIDs for ids. When an object is created, should I then generate a 10 character random string to use as public id, or is there a smarter approach?
旧的URL的例子:www.mysite.com/default.aspx?userId={id}
Example of old url: www.mysite.com/default.aspx?userId={id}
新的URL的例子:www.mysite.com/pwzd4r9niy
Example of new url: www.mysite.com/pwzd4r9niy
推荐答案
您可以使用任何类型的随机字符串发生器或GUID这个的。我不认为这是一个更聪明的方法。 (真知晶球提供了一个不错的选择,虽然,散列传入的URL)。
You can use any kind of random string generator or GUID for this. I don't think there is a much smarter approach. (Palantir offers a nice alternative though, hashing the incoming URL. )
剩下的就是相对简单:保持数据库表ID和目标URL;当一个请求时,查找ID,做一个头
重定向到目标URL。
The rest is relatively straightforward: Keep a database table with IDs and target URLs; When a request comes in, look up the ID and do a header
redirect to the target URL.
更多讨论href=\"http://www.codinghorror.com/blog/2007/08/url-shortening-hashes-in-practice.html\">这个博客帖子。
More discussion in this blog post.
也有重定向服务,在那里,现在使用的话,从字典列表创建一个URL。
There also are redirection services out there now that use words from a dictionary list to build a URL.
不幸的是,EvilURL不见了!它用来建立短网址
Sadly, EvilURL is gone! It used to create "short" URLs like
http://evilURL.com/donkey_porn-shotguns/cracking-virus-exploit
这是唯一的URL重定向服务的真正的值得的。 :)
that was the only URL redirection service really worthwhile. :)
而且,作为一个有点琐事,是最短人类已知的重定向服务(和,我想在最短的网页URL)。
And, as a bit of trivia, http://to
is the shortest redirection service (and, I think the shortest web URL) known to man.
这篇关于如何微小的网址工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!