Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikecao/shorty
A simple URL shortener for PHP
https://github.com/mikecao/shorty
php url-shortener
Last synced: 3 days ago
JSON representation
A simple URL shortener for PHP
- Host: GitHub
- URL: https://github.com/mikecao/shorty
- Owner: mikecao
- License: mit
- Created: 2011-08-19T23:21:46.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T16:08:47.000Z (over 4 years ago)
- Last Synced: 2024-07-31T19:45:57.317Z (6 months ago)
- Topics: php, url-shortener
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 264
- Watchers: 19
- Forks: 101
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- php-awesome - Shorty - 开源短链工具 (类库 / URL/Domain)
README
# Shorty
Shorty is a simple URL shortener for PHP.
## Installation
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:
http://example.com/?url=http://www.google.com
This will return a shortened URL such as:
http://example.com/9xq
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.http://example.com/?url=http://www.google.com&format=text
The possible formats are `html`, `xml`, `text`, and `json`.
## Whitelist
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:$shorty->allow('192.168.0.10');
## Requirements
* PHP 5.1+
* PDO extension## License
Shorty is licensed under the [MIT](https://github.com/mikecao/shorty/blob/master/LICENSE) license.