Skip to content
A simple URL shortener for PHP
Find file
Latest commit 4d7b50b Nov 10, 2015 @mikecao Merge pull request #1 from choopm/master
Fix: Unable to retrieve previously inserted URLs


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.

Something went wrong with that request. Please try again.