Getting_Startedback to top

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.

Features

  • Free and Open Source software.
  • Private (your links only) or Public (everybody can create short links, fine for an intranet)
  • Sequential or custom URL keyword
  • Handy bookmarklets to easily shorten and share links
  • Awesome stats: historical click reports, referrers tracking, visitors geo-location
  • Neat Ajaxed interface
  • Terrific Plugin architecture to easily implement new features
  • Cool developer API
  • Full jsonp support
  • Friendly installer
  • Sample files to create your own public interface and more

Credits

YOURLS is made by:

Keep up to date: follow Ozh and read the official YOURLS Blog

Installationback to top

Fresh Install

  1. Unzip the YOURLS archive
  2. Copy user/config-sample.php to user/config.php
  3. Open user/config.php with a raw text editor (like Notepad) and fill in the required settings
  4. Upload the unzipped files to your domain public_html or www folder
  5. Create a new database (see Configuration – you can also use an existing one)
  6. Point your browser to http://yoursite.com/admin/

Upgrade

  1. Backup the database!
  2. Unzip the YOURLS archive
  3. Upload files to your server, overwriting your existing install
  4. Point your browser to http://yoursite.com/admin/
  5. Tip: you can now move your config.php file to the /user directory

Configurationback to top

How to configure YOURLS in user/config.php.

MySQL settings

  • YOURLS_DB_USERYour MySQL username
    php define( 'YOURLS_DB_USER', 'joe' );

  • YOURLS_DB_PASSYour MySQL password
    php define( 'YOURLS_DB_PASS', 'MySeCreTPaSsW0rd' );

  • YOURLS_DB_NAMEThe database name
    php define( 'YOURLS_DB_NAME', 'yourls' );

  • YOURLS_DB_HOSTThe database host
    php define( 'YOURLS_DB_HOST', 'localhost' );

  • YOURLS_DB_PREFIXThe name prefix for all the tables YOURLS will need
    php define( 'YOURLS_DB_PREFIX', 'yourls__' );

Site options

  • YOURLS_SITEYour (short) domain URL, no trailing slash, lowercase
    If you pick the non-www version of your domain, don't use the www version in your browser (and vice-versa).
    php define( 'YOURLS_SITE', 'http://sho.rt' );

  • YOURLS_HOURS_OFFSETTimezone GMT offset
    php define( 'YOURLS_HOURS_OFFSET', '-5' );

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

  • YOURLS_UNIQUE_URLSAllow 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).
    php define( 'YOURLS_UNIQUE_URLS', 'true' );

  • YOURLS_COOKIEKEYA 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/cookie
    php define( 'YOURLS_COOKIEKEY', 'qQ4KhL_pu|s@Zm7n#%:b^{A[vhm' );

  • yourls_user_passwordsA 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.
    php $yourls_user_passwords = array( 'joe' => 'mypassword', );

URL Shortening settings

  • YOURLS_URL_CONVERTURL shortening method: base 36 or 62
    See FAQ for more explanations. php define( 'YOURLS_URL_CONVERT', '36' );

  • yourls_reserved_URLA list of reserved keywords that won't be used as short URLs
    Define here negative, unwanted or potentially misleading keywords.
    php $yourls_reserved_URL = array( 'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', 'gay' );

Optional settings

  • YOURLS_PRIVATE_INFOS
    If YOURLS_PRIVATE is set to true, you can still make stat pages public.
    php define( 'YOURLS_PRIVATE_INFOS', false );

  • YOURLS_PRIVATE_API
    If YOURLS_PRIVATE is set to true, you can still make your API public.
    php 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. php define( 'YOURLS_NOSTATS', false );

Advanced settings

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.

APIback to top

Features

  • Generate or get existing short URLs, with sequential or custom keyword
  • Get some statistics about your links: top clicked links, least clicked links, newest links
  • Output format: JSON, XML, or simple raw text
  • Authentify either with login/password or using a secure passwordless mechanism

Usage

You need to send parameters to http://yoursite.com/yourls-api.php either via GET or POST (remember to URL encode parameters if via GET). These parameters are:

  • A valid username / password pair, or your signature (see Passwordless API requests)
  • 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 return

xml <result> <url> <keyword>shorter</keyword> <url>http://somereallylongurlyouneedtoshrink.com/</url> <title>The Page Title</title> <date>2009-06-23 18:08:07</date> <ip>127.0.0.1</ip> </url> <status>success</status> <message>http://somereallylongurlyouneedtoshrink.com/ (ID: shorter) added to database</message> <title>The Page Title</title> <shorturl>http://yoursite.com/shorter</shorturl> <statusCode>200</statusCode> </result>

Sample file

There's a sample file included that serves as an example on how to play with the API.

Pluginsback to top

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.

There's a growing number of plugins available: check the Plugin list.

Documentation

Several sample plugins are included in the archive. Read the source and learn the concept. It's easy and fun!

Check the plugin API documentation to learn more

Themesback to top

Themes?

FAQback to top

Server requirements

  1. A server with mod_rewrite enabled
  2. At least PHP 5.2
  3. At least MYSQL 4.1
  4. Note: YOURLS can also run on Nginx and Cherokee

Server recommendations

Limitations

  • Maximum length of custom keyword is 200 characters
  • That makes about 8 sexdecillions of centillions of available URLs (seriously. That's a 355 digits number).

Difference Between Base 36 And Base 62 Encoding

  • Base 36 encoding uses 0123456789abcdefghijklmnopqrstuvwxyz for short URLs
  • Base 62 encoding uses 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  • Stick to one setting, don't change after you've created links as it will change all your short URLs!
  • Base 36 is the default and should be picked if you're not sure.

Getting a short domain name for your YOURLS install

  • Unless you plan on making it public and as popular as bit.ly, any shared hosting will be fine. Ozh runs all his YOURLS instance on Dreamhost and it works just great.
  • Domainr is a fun search tool that might inspire and help you
  • Aim for exotic top level domains (.in, .im, .li ...), they're often cheap and a lot are still available. Gandi is a pretty comprehensive registrar, for instance.

YOURLS needs its own .htaccess

  • You cannot install YOURLS and, say, WordPress, in the same directory. Both need to handle URLs differently and need their own .htaccess file.
  • If you want to install YOURLS on the same domain than your blog, give it its own (short) subdirectory, such as yourblog.com/s/ (for "short") or yourblog.com/x/ (for "exit")

If YOURLS generates 404 for your short URLs

  • Make sure mod_rewrite is enabled with your Apache server
  • Make sure your .htaccess file looks like this one
  • Eventually, check your server Apache configuration allows use of .htaccess (AllowOverride All directive, ask your server admin)

There is no index page at the root of the install

  • Indeed. It's intented. 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.

Uppercase letters in short URLs are eaten up, eg "OmgOzh" becomes "mgzh" !

  • Indeed. It's intented if you selected Base 36 (see above). Letters that don't belong to the character set, eg @#! or ABC, are removed.
  • If you want to force lowercase, you'll need a plugin.

Feedback, feature requests and bug reporting

  1. Please don't get in touch directly by mail or Twitter. Please.
  2. Check the Road Map for future features.
  3. Read all the wiki documents.
  4. Search in all the issues, open and closed.
  5. Eventually raise a new issue. To do so, please read the contribute guidelines. Thanks!

Communityback to top

YOURLS is open source, so the community of users plays a great role in its development, by contributing, helping others or giving feedback that helps improve the software.

Resources

  • The official YOURLS blog, for news, hints and showcase.
  • The wiki: advanced documentation, plugins, tips and more
  • Follow @YOURLS for hardcore development, and @Ozh for tips and news (and random geekiness too)

Showcase

Here are a few examples of sites running YOURLS with a unique design or concept

  • oe.cd — OECD's internal URL shortener with a neat interface and private features
  • freze.it — Shortens and saves a screenshot of a long URL
  • xib.me — A nicely styled YOURLS public interface
  • girv.in — John Girvin's YOURLS setup with all links in a sortable display (and its source)
  • rml.me — A personal URL shortener front page showing new links and most clicked links
  • vt802.us — Defined as "The World's First Vermont-centric URL Shortener"
  • yourwish.es — Easily share an Amazon wishlist
  • vbly.us — Public YOURLS setup and early adopter, run by famous sex writer Violet Blue as "the internet's first and only sex-positive url shortener", once taken down by Libya (story)

YOURLS and other platforms or frameworks

  • WordPress — There are numerous WordPress plugin with YOURLS support. The official plugin is no longer maintained. YOURLS Link Creator is recommended.
  • Drupal — Allows for the automatic creation of short urls using a YOURLS installation
  • Perl — WWW-Shorten-Yourls is a Perl module to shorten URLs using YOURLS
  • Ruby — A Ruby wrapper for the YOURLS API
  • Python — A Python client for YOURLS
  • VB .Net — A VB .Net 4.0 wrapper for the YOURLS API
  • Javascript — JavaScript bindings for the YOURLS API to leverage JSONP support
  • CakePHP — Plugin which integrates CakePHP with Yourls
  • status.net — A plugin for status.net to use YOURLS

YOURLS works with your favorite sofware or device

  • Tweetie 2 — How to set up Tweetie2 so it uses your own service
  • Tweetbot — Make Tweetbot run with YOURLS
  • Seesmic — Use YOURLS with Seesmic
  • Twitterfeed — Use Twitterfeed with YOURLS
  • Mac Client — Simple app to have a global keyboard shortcut send a link to YOURLS
  • Android: URLy and URL Shortener — Android apps that plays nice with YOURLS
  • iOS — Clicklytics track links using YOURLS on iPhone and iPad
  • Chrourls — Google Chrome quick link shortening addon for YOURLS
  • Firefox Addon — Firefox Addon for YOURLS
  • Textexpander and YOURLS — Making YOURLS and Textexpander on the Mac play together

More stuff to do with YOURLS

"Celebrity endorsements", sort of.