I'm focusing on a URL shortening site which uses PHP, MySQL and Apache. General concept of URL shortening when i take a look at free projects: user provides a URL link and also the system will get ID for your link from database. Then convert the ID X base system (I'm using base 36). Then use Apache mod_rewrite and make reduced URL after which redirect. Do all the URL shortening sites work like this or perform some make use of a different formula aside from this? And then any idea to make a positive change using their company URL shortening systems?
I believe you're quite on the proper way.
One factor I'd not do as if you stated, though, is all about this part :
then use apache mod_rewrite and make shorten url after which redirect.
I do not think I'd create an Apache RewriteRule, nor use
When receiving an short url, like
short.com/MYID, Id would :
- decrypt the "MYID" part towards the id number in DB
- fetch the URL from database
- just redirect to that particular URL from some server code (like PHP, while using
A little such as this I suppose :
// fetch $urlFull from DB (akin to the MYID received in GET) header('HTTP/1.x 301 Moved Permanently') header('Location: ' . $urlFull) die
(edit) If by
mod_rewrite you meant "transform short.com/MYID to short.com/id=MYID", oh, yes, within this situation, obviously !
I am using something similar to this on a single of my sites, btw :
RewriteEngine on RewriteCond % !^/index.php RewriteRule ^(.*)$ /index.php?hash=$1 [L]
Hope this can help :-)
If you wish to make a move not the same as other URL shortening sites, discover a method to make certain the hyperlinks don't break in case your site disappears! I'm not sure how to get this done, I believe it's most likely impossible...
Only a security note: Don't redirect straight to the website from the reduced url when not beneath your control/domain - possess a website landing page in which the user can easily see the particular url and choose whether or not to continue or otherwise...
You should use bit.ly (twitter uses this). You will find some APIs that can be used to call and fetch reduced Web addresses.
Also discuss shortening Web addresses, you can just make use of a table such as this
CREATE TABLE `urls` ( `id` varchar(255) NOT NULL default '', `url` text NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Where one can possess the
id (in base 36 to avoid exhaustion of 32 bit integers) to become the reduced id - http://host/?id
so when you call the URL http://host/?As2dD24B, it'll lookup the matching ID and URL, then redirects towards the URL. simple?
Also bear in mind that you could expand your base 36. I'm presuming that the base 36 is: a-z and -9. You can include inside a-Z (another 26) along with other symbols (for example ?,:*&lifier^%$#@).
Being associated with the topic... Url Shorteners: Wrecking the net Since 2002