logIt Log Around The Clock

URL Shortener From Yourls (1)

We can self-hosted URL Shortener service. I tried open source php-based URLShort and Yourls. I later choose Yourls.

Both of course based on .htaccess manipulation (mod_rewrite of Apache must be enabled). I install Yourls in side http://my.web/somedir. To make my short URL to use something like http://my.web/xGf12 instead of http://my.web/somedir/xGf12, I run the regular install with that somedir as based URL, but then create .htaccess in http://my.web/.htaccess (instead of http://my.web/somedir/.htaccess) However, I intend to use prefix x for the shorten URL. Here is how the regular expression implemented:

# BEGIN YOURLS
 
RewriteEngine On
RewriteBase /somedir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(x[0-9A-Za-z]+)/?$ /somedir/yourls-go.php?id=$1 [L]
RewriteRule ^(x[0-9A-Za-z]+)\+/?$ /somedir/yourls-infos.php?id=$1 [L]
RewriteRule ^(x[0-9A-Za-z]+)\+all/?$ /somedir/yourls-infos.php?id=$1&all=1 [L]
 
# END YOURLS

Leave a Reply