Phillip B Oldham
Phillip B Oldham

Reputation: 19385

Compress/obfuscate URL to use in rewrite?

I need to add the URL of a 3rd-party website to a url, but I'd like to compress/obfuscate the host part. Are there any algorithms I can use which will hash the url, but also allow un-hashing?

For example; the url is http://www.twitter.com/myusername. What I'm serving currently (as a html link) is http://mysite.net/bounce/www.twitter.com/username. What I'd like to serve is something like http://mysite.net/bounce/X5nsSkdWfA/username, and have the bounce script decode |^/bounce/(.*)/| back to www.twitter.com.

I'd like to do this without storing the hash anywhere.

Suggestions?

Upvotes: 0

Views: 622

Answers (2)

assaqqaf
assaqqaf

Reputation: 1585

you can use technique exist in this tut..

BUILDING A URL SHORTENER

you can use the function to shortern url and convert it back, by extracting it from url.

Upvotes: 0

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143229

You can use, for instance, ROT13 for obfuscating ;-)

$ echo twitter.com | rot13
gjvggre.pbz

Then you can use base64

$ echo twitter.com | base64
dHdpdHRlci5jb20K

Naturally, they don't compress. You can come with something yourself for squeezing a few bits out of it.

Upvotes: 5

Related Questions