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
- Create a unique identifier for a given URL, store it in a database,
- when user visits short url, lookup the original URL in the database,
- 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
精彩评论