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!
Source: Tips4all
Here's what I recommend.
ReplyDelete1) 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