Short URL System: How to Redirect Custom URLs?

I'm trying to make a tinyurl-like service for my company, and so far it looks good, but now I have a problem that I can’t solve.

Suppose the URL I create is "www.thecompanyiworkfor.com/shorturl/2jh62/". I suppose I need to use some script, say, "redirect.php", where I go to the databank, look for this short URL, find the source and redirect the headers.

My question is: how can I make this "www.thecompanyiworkfor.com/shorturl/2jh62/" open "redirect.php" and what can I access "shorturl" as a parameter? I thought I would need to do something with .htaccess, but I'm not quite sure what to do ...

Help me please!

+7
source share
1 answer

Here is what I recommend.

1) Create an additional domain (s.thecompanyiworkfor.com). The manager will be easier to manage, and you will avoid conflict with .htaccess, because this folder is separated from the main WWW folder.

eg:

s.thecompanyiworkfor.com => /home/thecompanyiworkfor.com/s_public_html/ www.thecompanyiworkfor.com => /home/thecompanyiworkfor.com/public_html/ 

2) Use this .htaccess in /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 /home/thecompanyiworkfor.com/s_public_html/index.php you can check which code matches the url and redirect. If not found, redirect to www.thecompanyiworkfor.com

+12
source

All Articles