About YOURLS

What is YOURLS

YOURLS stands for Your Own URL Shortener. It is a small set of PHP scripts that will allow you to run your own URL shortening service (a la TinyURL or bitly).

Running your own URL shortener is fun, geeky and useful: you own your data and don't depend on third party services. It's also a great way to add branding to your short URLs, instead of using the same public URL shortener everyone uses.

YOURLS Features

Free and Open Source software.

Private (your links only) or Public (everybody can create short links, fine for an intranet)

YOURLS_PRIVATE
Private means the admin area will be protected with login/pass as defined below. See Private or Public for more.Example:define( 'YOURLS_PRIVATE', 'true' );

YOURLS_UNIQUE_URLS
Allow multiple short URLs for a same long URL
Set to true to allow only one pair of shortURL/longURL (default YOURLS behavior), or to false to allow creation of multiple short URLs pointing to the same long URL (as bit.ly does)Example:define( 'YOURLS_UNIQUE_URLS', 'true' );

YOURLS_COOKIEKEY
A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: generate a unique one at http://yourls.org/cookieExample:define( 'YOURLS_COOKIEKEY', 'qQ4KhL_pu|s@Zm7n#%:b^{A[vhm' );

yourls_user_passwords
A list of username(s) and password(s) allowed to access the site if private
Passwords can either be in plain text, or encrypted: see http://yourls.org/userpassword for more information.Example:'joe' => 'mypassword'

URL Shortening settings

YOURLS_URL_CONVERT
URL shortening method: base 36 or 62. See FAQ for more explanations

Optional settings

YOURLS_PRIVATE_INFOS
If YOURLS_PRIVATE is set to true, you can still make stat pages public. To do so, define with:define('YOURLS_PRIVATE_INFOS', false);

YOURLS_PRIVATE_API
If YOURLS_PRIVATE is set to true, you can still make your API public. To do so, define with:define('YOURLS_PRIVATE_API', false);

YOURLS_NOSTATS
If YOURLS_NOSTATS is set to true, redirects won't be logged and there will be not stats available.

Advanced settings

YOURLS will look for the MySQL extension PDO, MySQLi or MySQL, in that order. If you want to force usage of one particular extension, add the following line to your config.php:define( 'YOURLS_DB_DRIVER', 'mysqli' );

You can install YOURLS behind a firewall or a proxy: see Proxy Support

File includes/load-yourls.php contains a few more undocumented but self explanatory and commented settings. Add them to your own config.php if you know what you're doing.

Plugins for YOURLS

Plugins?

Plugins are additional PHP scripts that extend the functionalities or features of YOURLS. The core of YOURLS is designed to be as light as possible and avoid bloat (implementing functions not everybody needs) and to allow for easy customization.

Using the plugin architecture, you can add new features to YOURLS without having to modify core files. This way, your changes won't be lost when you upgrade your YOURLS installation and you can easily activate and deactivate a plugin from the admin interface.

The requested action: "shorturl" (get short URL for a link), "expand" (get long URL of a shorturl), "url-stats" (get stats about one short URL), "stats" (get stats about your links) or "db-stats" (get global link and click count)

With action = "shorturl" :

the url to shorten

optional keyword and title for custom short URLs

output format: either "jsonp", "json", "xml" or "simple"

With action = "expand" :

the shorturl to expand (can be either 'abc' or 'http://site/abc')

output format: either "jsonp", "json", "xml" or "simple"

With action = "url-stats" :

the shorturl for which to get stats (can be either 'abc' or 'http://site/abc')

output format: either "jsonp", "json" or "xml"

With action = "stats" :

the filter: either "top", "bottom" , "rand" or "last"

the limit (maximum number of links to return)

output format: either "jsonp", "json" or "xml"

With action = "db-stats" :

output format: either "jsonp", "json" or "xml"

Sample requests

Example of a GET request with Javascript (using jQuery) to shorten a URL

Random versus sequential short URLs

Out of the box, YOURLS generates sequential short URLS (ie ab31, then ab32 and so on)

If you prefer random short URLs (ie j3kz1 then 13hz7 like Bitly does), just activate the plugin that comes with YOURLS.

"Stats don't update as I think they should", "difference with Google Analytics", etc...

Out of the box, YOURLS updates traffic stats every time a short URL is requested. Period.

This said, some clients (like indexing bots, your internet browser) may skip requesting a short URL if they have the final destination known in cache.

Conversely, other stat tools may use different techniques to track hits (using javascript or not, using IP adress, filtering multiple requests by same client, etc...)

Bottom line: your mileage may vary with different tools, but there is no bug in YOURLS regarding that matter.

There is no index page at the root of the install

Indeed. It's intended. It's up to the user to make what they need. Some will redirect the root to a different place, some make a public interface for anyone to shorten links, some make a portfolio. You make it.

If you want to make a public interface and run your own little bitly.com, there's a sample file provided as an example: sample-public-front-page.txt. This implies important issues to deal with: spam, performance and security. Read Public Shortening for important information.