Personal URL Shortener In Three Lines Of Code
Having your own URL shortener service has some benefits over using a third party service. To name two: more exposure for your personal domain and full access to web traffic data. But if, for whatever reason, you don't want to host your own here is a quick hack using the Nginx webserver.
Choose a reliable URL shortener service. I'm betting on Google's service at http://goo.gl/. Add the following three lines to the server section of your Nginx configuration:
location ~ /u/(.*)$ {
rewrite ^/u/(.*)/?$ http://goo.gl/$1 redirect;
}
Generate a shortened URL at http://goo.gl/ and replace the goo.gl domain with your own. In my case:
http://goo.gl/nlthH > http://larsman.nl/u/nlthH
When users click on your shortened URL they will be redirected to Google's shortened URL which in turn will redirect users to their final destination. This all happens in a flash, try it .
By adding a unique path to your shortened URLs you'll be able to differentiate them from other content on your site. Now using grep you can quickly scan through the Nginx logs for clicks:
grep '/u/' /var/log/nginx/larsman.nl.access.log