I've been thinking of implementing a "short-URL" scheme for my site, so I don't have to use TinyURL. I want to own my links and relying on TU or other services is something I don't like.
So here's what I want to do:
1) Let's say that I write an entry and it gets posted to what I'll call a "canonical" URL. This link would look something like http://www.myawesomewebsiteontheinternets.com/2009/04/04/post-title-goes-here.html. (Please note that my use of the word "canonical" should not be confused with the rel=canonical tag attribute).
2) I would also create for the above post a second "short" URL, such as http://site.com/01a4d that redirects the user automatically (TinyURL style) to http://www.myawesomewebsiteontheinternets.com/2009/04/04/post-title-goes-here.html. (Note: in this case, "site.com" would refer to a second, shorter, "parked" domain on the server that would let me create short links to content.
Does anyone have any idea how I might do this?
Reported on Movable Type 4.2
You would need a simple table with short tag (just the 01a4d for example) and the redirect url.
You will need a cgi script that searches the table for the directory requested and the redirects to the matching redirect url.
Use the script as your 404 handler.
If site.com is being used strictly as a redirect site, what advantage does a cgi script have over a redirect from a htaccess file?
The problem is that .htaccess is read every time a page on the site is loaded and if you get more than 10 or 20 lines in a .htaccess file, it starts affecting site performance noticeably.
Then you have two choices: put it in httpd.conf or write a PHP or CGI script to do the redirection. For the latter, all you need is a simple PHP script with a lookup table inside a hashtable. $_SERVER{'REQUEST_URI'}; contains the requested URI that you'd need for looking up the corresponding correct URL, and then you just do a HTTP redirect.
It is one additional line to .htaccess or global Apache config to add your custom 404 handler. This is similar to how most dynamic publishing systems work (including WP and MT). You request a page that does not exist, the 404 handler then generates the page you need from the database.