Simple PHP URL shortener, as used on
PHP Nginx ApacheConf
Latest commit f64ee34 Feb 4, 2017 @lekkerduidelijk lekkerduidelijk committed with Add nginx.conf
Add nginx configuration example for rewrite rules.

Closes #12.

Simple PHP URL shortener

Requires PHP ≥ 5.4.0 or higher.


  1. Download the source code as located within this repository, and upload it to your web server.
  2. Use database.sql to create the redirect table in a database of choice.
  3. Edit config.php and enter your database credentials.


  • Redirect to Twitter when given a numerical slug, e.g.
  • Redirect to your Twitter account when @ is used as a slug, e.g.
  • Redirect to your Google Plus account when + is used as a slug, e.g.
  • Redirect to your main website when no slug is entered, e.g.
  • Redirect to a specific page on your main website when an unknown slug (not in the database) is used, e.g.
  • Ignores weird trailing characters (!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, @, :, ;, <, =, >, [, \, ], ^, _, {, |, }, ~) in slugs — useful when your short URL is run through a crappy link parser, e.g. → same effect as visiting
  • Generates short, easy-to-type URLs using only [a-z] characters.
  • Doesn’t create multiple short URLs when you try to shorten the same URL. In this case, the script will simply return the existing short URL for that long URL.
  • DRY, minimal code.
  • Correct, semantic use of the available HTTP status codes.
  • Can be used with Twitter for iPhone. Just go to SettingsServicesURL ShorteningCustom… and enter http://yourshortener.ext/shorten?url=%@.

Favelets / Bookmarklets



Shorten this URL



This script is available under the MIT license.