Question

Possible Duplicate:
how to shorten the url in a mathematical approach

Its a college django project.. where I can't really setup a database model to store dynamically generated URLs and redirect to short urls based on hashed primary key.. etc

I am thinking in lines of encrypting URL using some algorithm and decrypt on the server. Initially, I thought of using md5 hash but I guess we can't decrypt.

My actual URL would look like:

http://mydomain.com/photo?friend_name=dennis&me_name=ritchie&ping_url=http%3A%2F%2Fmydomain.com%2Fimg%3Furl%3Dhttps%3A%fsjcsd.googleueusercontent.com%2F-Sf6bP2nOKa8%2FUMaw8vv0QLI%2FAaaddjhnkchkjda7E%2Fs800%2FHosbsco.png%26message%3Dhi+dude

I am thinking it to convert into:

http://mydomain.com?encode=hksfhsfksuhkvbkjnukvns

Then on server side I thinking to convert hksfhsfksuhkvbkjnukvns back to actual string.

Is there any Python Lib I have

Was it helpful?

Solution

You can go with url compression + encrypting/base64 approach.

For compressing you can check python's zlib or any other lossless compression libraries (lzma, etc), then convert compressed binary string to ascii by base64. For your information, zlib + base64 for your url is worse than the original url.

But the url may never be as short as you expect, simply because the url content have a lot of information, bad compression ratio, etc. So it's possible that this solution will never meet the need for applications with text length limit (like twitter).

So If you wanna a REALLY short url, there must be somewhere to store the short-long pair.

Keeping those in mind, and I googled for "url shortener" and a lot popped out.

These are third party web applications just to do this job:

Hope you can use a third party app, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top