Skip to content

Using self-hosted URL shortener YOURLS

Update

This works better:
[cclN_php]define(‘YOURLS_SITE’, ‘http://’ . $_SERVER[‘SERVER_NAME’]);[/cclN_php]
assuming yourls is installed in the root directory of your web site (http://foo.bar.com/ for example). If otherwise (http://foo.bar.com/yourls/) you’d want:
[cclN_php]define(‘YOURLS_SITE’, ‘http://’ . $_SERVER[‘SERVER_NAME’] . ‘/yourls’);[/cclN_php]

Original Post

I’m now using Shorten2Ping to get my post updates from my blogs to Ping.FM (from which it goes to LinkedIn, Identi.ca and army.twit.tv).

While setting this up, I noticed that there’s an option for a self-hosted URL shortener called YOURLS. This thing rocks! It shortens URL’s, collects statistics, and allows custom shortened URL’s.

I wanted to use the same install (database etc) across all my blogs (poojanblog.com, www.circuitdesign.info, tech.poojanblog.com). WebFaction makes doing so very easy: you can tie any subdirectory of a domain to a specific “web app” (UNIX directory). So, for example, both poojanblog.com/u and www.circuitdesign.info/u point to the same directory on my web host.

The only issue with this is that YOURLS returns one and only one domain for the shortened URL, set by a PHP define for YOURLS_SITE in includes/config.php.

Luckily, I found a way around this. I put the following in config.php:

[cclN_php]define(‘YOURLS_SITE’, dirname($_SERVER[‘REQUEST_URI’])); // LOL. Wild guess.[/cclN_php]

This happens to be taken from includes/load-yourls.php as a fall-back if the YOURLS_SITE isn’t defined. Basically, it picks up the domain name from the HTTP header.

Be the first to like.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*