A simple URL shortener for PHP
Clone or download
Latest commit e56f50c Apr 6, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Add license file. Jan 18, 2014
README.md Add license file. Jan 18, 2014
config.php Added configuration options for salt and padding. Jan 21, 2014
database.sql Update Max URL Length Jan 25, 2017
index.php Added configuration options for salt and padding. Jan 21, 2014
shorty.php Patch homepage code Apr 6, 2018



Shorty is a simple URL shortener for PHP.


1. Download and extract the files to your web directory.

2. Use the included database.sql file to create a table to hold your URLs.

3. Configure your webserver.

For Apache, edit your .htaccess file with the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [QSA,L]

For Nginx, add the following to your server declaration:

server {
    location / {
        rewrite ^/(.*)$ /index.php?q=$1;

4. Edit the config.php file.

Generating short URLs

To generate a short URL, simply pass in a url query parameter to your Shorty installation:


This will return a shortened URL such as:


When a user opens the short URL they will be redirected to the long URL location.

By default, Shorty will generate an HTML response for all saved URLs. You can alter the response format by passing in a format query parameter.


The possible formats are html, xml, text, and json.


By default anyone is allowed to enter a new URL for shortening. To restrict the saving of URLs to certain IP addresses, use the allow function:



  • PHP 5.1+
  • PDO extension


Shorty is licensed under the MIT license.