I'm trying to make a tinyurl-like service for my company, and so far looks good, but now I have a problem I can't solve.
Lets say the URL I generate is "www.thecompanyiworkfor.com/shorturl/2jh62/". My guess is I have to use some script, lets say "redirect.php", where I access the databank, look for that short url, find the original one, and redirect with headers.
My question is, how can i make that "www.thecompanyiworkfor.com/shorturl/2jh62/" open "redirect.php" and that I can access the "shorturl" as a parameter? I thought I would have to do something with .htaccess, but I'm not really sure what should I do...
Help please!
URL shorteners use the 301 redirects to forward browsers from a short link location to the final destination. A 301 redirect passes the link equity – or SEO value – of a short URL on to this new location.
Bitly is a powerful (and popular) tool for shortening URLs. The free service lets you shorten links using the Bit.ly domain name, while the premium service lets you use your own custom domain name. Bitly has features like link retargeting in the paid version.
Like TinyURL, Tiny.cc is a quick and easy free URL shortener. On Tiny.cc, you can post a long URL into the box on the front page, add an optional custom link ending, and click the button to shorten links for free.
Here's what I recommend.
1) Create a sub domain (s.thecompanyiworkfor.com). It will be easier to manager and you avoid conflict with .htaccess since this folder is separated from the main WWW folder.
for example:
s.thecompanyiworkfor.com => /home/thecompanyiworkfor.com/s_public_html/
www.thecompanyiworkfor.com => /home/thecompanyiworkfor.com/public_html/
2) Use this .htaccess in the /home/thecompanyiworkfor.com/s_public_html/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^index\.php
RewriteRule ^([a-z0-9\-]+)(\/?)$ index.php?code=$1 [L,NC,QSA]
Then in your /home/thecompanyiworkfor.com/s_public_html/index.php
you can check which code correspond to which URL and redirect. If not found, redirect to www.thecompanyiworkfor.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With