开发者

How does short URLS work? [duplicate]

开发者 https://www.devze.com 2023-02-17 11:24 出处:网络
This question already has answers here: 开发者_开发技巧 Closed 11 years ago. Possible Duplicate: How do short URLs services work?
This question already has answers here: 开发者_开发技巧 Closed 11 years ago.

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.


The 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

  • Will go to the tinyurl server
  • The server will lookup what full URL matches so-hints
  • The server will issue a redirect to the browser to go to the full URL


  1. Create a unique identifier for a given URL, store it in a database,
  2. when user visits short url, lookup the original URL in the database,
  3. return a HTTP 3xx (redirect) status code to the client with the actual address.

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:

  • 7 Open Source And Free URL Shortener Scripts To Create Your Own


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.


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


They manage a list of short to long URLs and redirect each request to short URL to its original one

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号