Url shortening. The Complete Picture.


What is Url shortening?? U just give a BBBBBBBBBBBIIIIIIIIIIIIIIIIIIIIGGGGGGGGGGGGGG url as input and it’ll give you a short url with which you can access ur BIG url.

For example  http://www.chaaps.com/url-shortening…mplete-picture.html  becomes http://bit.ly/aIlWqJ .

So wat does that mean ? Both these urls are just alias !!.

Now a question . Why do this ? cos its easier to share smaller url. Now that you are clear with what it is.

Now i’ll share with you how you can build ur own url shortner site 🙂 oh yeah….All yours

Things you need



3:Googling skills

Steps to create the ultimate site :p

Step 1: Buy a domain name which is very short. Ex: www.ul.in

Step 2 : Get a hosting Service . now a days u get one for 500 bucks a year.

Step 3: create a database.( http://bit.ly/1roQbE )

Step 4: create a table ( http://bit.ly/13aXsN)

with two columns(distinct_guid,long_url)

Step 5: create a index for this table and apply other methods to make access to this table faster.(just google),

Step 6: Create two  php files

Step 7: First a Php to allow someone to shorten url

this php must be able to take in the long url as a parameter

on Taking in looong url

generate a random number  like distinct_guid =   uniqid(rand(99999999999999,99999999999999999));

make an entry in the table you created distinct_guid,long_url

finally the shortened  url will be www.ul.in/”distinct_guid”

Step 8: ok now we have shortened the url next create the real deal php

in the .htaccess file  edit make an entry for this

RewriteEngine on
RewriteRule .* theRealDeal.php

in this theRealDeal.php read the distinct guid with help of this   $_SERVER[‘REQUEST_URI’];

on getting the distinct guid you’ll need to forward to the long url. How do you do that ??

from the table we created get the long url for the associated Distinct guid

then use php header redirect to redirect to the long url

header( ‘Location: “{$long_url}”‘ );

There you go . The simplest way  to create your own url Shortener.

make sure you don have any html content in theRealDeal.php

Note:- it may not be as easy as it sounds.:p If you have any questions.Leave a comment and i’ll help you.