Iis – Creating arbitrary urls that work like redirecting virtual directories

iisurlvirtualdirectories

I'm a complete newbie to server administration, so I'm not even sure if I'm posting this in the right place. If this seems to be a bad question, please respond correctly. Thank you.

I have been wondering for some time how sites such as URL shorteners work. For example, a shortened url with the popular service bit.ly looks like: http://bit.ly/2bgrkx

My question is, how are their servers set up to handle these urls with unique shortcodes at the end? And also, how could this handling be implemented in an IIS environment, with a different purpose of course, not URL shortening. For example, I also saw what twtvite.com was doing with these urls.

I've considered that they could be possibly creating virtual directories that redirect, but that seems a little too out of the ordinary.

Thank you very much, I hope this question isn't too out-of-place.

Best Answer

Most URl shorteners work like this - all requests, who are not requesting CSS / or other static files are routed to script, which found corresponding real URL from short URL identifier.

Then there are 2 ways: a)Sending HTTP header, which orders browser to redirect. Most popular choice is 302 Found . According to HTTP specs, its temporary redirect, but most browsers implement that as permament redirect. Better choice is 301 Moved permamently. b)Sending html document, with META tag, which says browser to redirect. Mostly, thats bad idea, because all redirects will be temporary and valid HTML doc is more bandwith consuming than simple HTTP header.And correct way is to do such things at protocol, not content level.

If you want to see how specific URL shortening services works, you can use Firebug (https://addons.mozilla.org/en-US/firefox/addon/1843) to see all requests, and responses with HTTP headers.

In apache you can use mod_rewrite, to rewrite urls, in IIS - http://www.isapirewrite.com/ (proabaly there is better solution, but I am not active IIS user any more).

Related Topic