readme.html
[➤
](#About;about)[➤
](#About;what)
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.
[➤
](#About;features)
[➤
](#About;screenshots)
Main admin dashboard
Stats for each short URL
[➤
](#About;download)
Download YOURLS from GitHub and see see the Install guide
[➤
](#About;credits)
YOURLS is made by awesome people.
Keep up to date: read the official YOURLS Blog.
[➤
](#Install;fresh)
user/config-sample.php to user/config.phpuser/config.php with a raw text editor (like Notepad) and fill in the required settingspublic_html or www folderhttp://your-own-domain-here.com/admin/[➤
](#Install;auto)
The documentation on docs.yourls.org is full of important information. Regarding installation, you'll find help for Apache and Nginx.
You will also find numerous unofficial installation guides on Awesome YOURLS, a curated list of resources.
[➤
](#Install;upgrade)
http://your-own-domain-here.com/admin/[➤
user/config.php)](#Config;configuration)[➤
](#Config;mysql)
YOURLS_DB_USERYOURLS_DB_PASSYOURLS_DB_NAME: The database nameYOURLS_DB_HOSTYOURLS_DB_PREFIX[➤
](#Config;site)
YOURLS_SITEYOURLS_PRIVATEYOURLS_UNIQUE_URLSYOURLS_COOKIEKEYyourls_user_passwords[➤
](#Config;urlsettings)
YOURLS_URL_CONVERTyourls_reserved_URL[➤
](#Config;optional)
YOURLS_PRIVATE_INFOSYOURLS_PRIVATE is set to true, you can still make stat pages public. To do so, define with:YOURLS_PRIVATE_APIYOURLS_PRIVATE is set to true, you can still make your API public. To do so, define with:YOURLS_NOSTATSYOURLS_NOSTATS is set to true, redirects won't be logged and there will be not stats available.[➤
](#Config;advanced)
includes/Config/Config.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;plugins-for-yourls)[➤
](#Plugins;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.
[➤
](#Plugins;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
[➤
](#API;yourls-api)[➤
](#API;apifeatures)
[➤
](#API;apiusage)
You need to send parameters to http://your-own-domain-here.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" :
url to shortenkeyword and title for custom short URLsformat: either "jsonp", "json", "xml" or "simple"With action = "expand" :
shorturl to expand (can be either 'abc' or 'http://site/abc')format: either "jsonp", "json", "xml" or "simple"With action = "url-stats" :
shorturl for which to get stats (can be either 'abc' or 'http://site/abc')format: either "jsonp", "json" or "xml"With action = "stats" :
filter: either "top", "bottom" , "rand" or "last"limit (maximum number of links to return)format: either "jsonp", "json" or "xml"With action = "db-stats" :
format: either "jsonp", "json" or "xml"With action = "version" :
format: either "jsonp", "json", "xml" or "simple"[➤
](#API;apiexample)
Example of a GET request with Javascript (using jQuery) to shorten a URL
var api\_url = 'http://sho.rt/yourls-api.php'; var response = $.get( api\_url, { username: "your\_username", password: "your\_password", action: "shorturl", format: "json", url: "http://ozh.org/" }, // callback function that will deal with the server response function( data) { // now do something with the data, for instance show new short URL: alert(data.shorturl); } );
Example of a POST request with PHP to expand a short URL
<?php $username = 'your\_username'; $password = 'your\_password'; $api\_url = 'http://sho.rt/yourls-api.php'; // Init the CURL session $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, $api\_url); curl\_setopt($ch, CURLOPT\_HEADER, 0); // No header in the result curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, true); // Return, do not echo result curl\_setopt($ch, CURLOPT\_POST, 1); // This is a POST request curl\_setopt($ch, CURLOPT\_POSTFIELDS, array( // Data to POST 'shorturl' =\> 'ozh', 'format' =\> 'json', 'action' =\> 'expand', 'username' =\> $username, 'password' =\> $password )); // Fetch and return content $data = curl\_exec($ch); curl\_close($ch); // Do something with the result. Here, we echo the long URL $data = json\_decode( $data ); echo $data-\>longurl;
[➤
](#API;apireturn)
Sample return in JSON format for the shorturl action
{ "url": { "keyword": "ozh", "url": "http:\/\/ozh.org", "title": "Ozh RICHARD \u00ab ozh.org", "date": "2014-10-24 16:01:39", "ip": "127.0.0.1" }, "status": "success", "message": "http:\/\/ozh.org added to database", "title": "Ozh RICHARD \u00ab ozh.org", "shorturl": "http:\/\/sho.rt\/1f", "statusCode": "200" }
Sample return in XML format for the expand action
\<result\> \<keyword\>ozh\</keyword\> \<shorturl\>http://sho.rt/ozh\</shorturl\> \<longurl\>http://ozh.org/\</longurl\> \<message\>success\</message\> \<statusCode\>200\</statusCode\> \</result\>
[➤
](#API;apisample)
There's a sample PHP file included that serves as an example on how to play with the API
[➤
](#API;expand_api)
You can easily implement custom API actions with a plugin. See the plugin list for examples.
[➤
](#FAQ;theFAQ)[➤
](#FAQ;requirement)
[➤
](#FAQ;limitations)
[➤
](#FAQ;base3662)
0123456789abcdefghijklmnopqrstuvwxyz for short URLs0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz[➤
](#FAQ;shortdomain)
[➤
](#FAQ;htaccess)
[➤
](#FAQ;does404)
[➤
](#FAQ;sequential)
ab31, then ab32 and so on)j3kz1 then 13hz7 like Bitly does), just activate the plugin that comes with YOURLS.[➤
](#FAQ;stats)
[➤
](#FAQ;noindex)
sample-public-front-page.txt. This implies important issues to deal with: spam, performance and security. Read Public Shortening for important information.[➤
OmgOzh" becomes "mgzh" !](#FAQ;lowercase)
@#! or ABC, are removed.[➤
](#FAQ;feedback)
[➤
](#More;community)
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.
[➤
](#More;ressources)
[➤
](#More;showcase)
YOURLS is used by dozens of thousands of users : inviduals, anonymous, celebrities, universities, small teams, huge companies.
It is or has been used by Epic Games, the NASA, McLaren, Dreamhost and many more.
You will find several examples of YOURLS implementations on Awesome YOURLS.
[➤
](#More;frameworks)
Contributors have made YOURLS work with various platforms, programming languages, applications or tools : Laravel, Symfony, WordPress, Perl, Ruby, Android, iOS, you name it.
Head to Awesome YOURLS and find the missing tool you didn't know you were needing.