Tutorial: A Simple URL Redirector - Part 1
A few months ago I made a simple URL redirector to mimic tinyurl.com’s service. You may use it if you like it by the way. The redirector is located at http://r.bango29.com/. The basic ingredients are the usuals: Apache with mod_rewrite PHP MySQL Before getting into the actual coding, I did the htaccess part first. In any Apache installation, we can use htaccess files to extend Apache's capabilities. The is actually only an extension and if you're working on a Windows platform, you can only rename it by using the command line. The file must be exactly named: .htaccess Just put the htaccess on your root public html directory and type in the codes below: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/\.]+)/?$ /index.php?q=$1 [L] Now let's go into the details of the above code. The first line query Apache if the rewrite module is available or not. We then activate the rewrite engine and set our base URL as our rewrite base. The fourth line is where the trickyness start. It’s basically telling Apache if the visitor’s request is not a file (indicated by the !-f flag) then proceed to our next condition. The next condition query Apache if it is a directory or not (indicated by the !-d flag). ...