Skip to content

Using self-hosted URL shortener YOURLS


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 ( for example). If otherwise ( 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, and

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 (,, 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 and 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 *