PHPackages                             cndrsdrmn/short-url - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cndrsdrmn/short-url

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cndrsdrmn/short-url
===================

A lightweight and flexible Laravel package for generating and managing short URLs.

v0.1.0(1y ago)00MITPHPPHP ^8.3

Since Dec 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/cndrsdrmn/short-url)[ Packagist](https://packagist.org/packages/cndrsdrmn/short-url)[ RSS](/packages/cndrsdrmn-short-url/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

**Short URL Package**
=====================

[](#short-url-package)

[![Packagist Version](https://camo.githubusercontent.com/13bd2adb4901774c1466c6f5b9113a0f3ffbeafb7013cff97fc3355ea38a94a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636e64727364726d6e2f73686f72742d75726c3f6c6162656c3d737461626c65)](https://packagist.org/packages/cndrsdrmn/short-url)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/f93ac0371b07ccec7b3c5ab428f813d1df3020522124bb126786430e665d95d9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636e64727364726d6e2f73686f72742d75726c2f74657374732e796d6c3f6c6f676f3d676974687562266c6162656c3d4349)](https://github.com/cndrsdrmn/short-url/actions)[![GitHub License](https://camo.githubusercontent.com/5ad65cd44d2e663923720c3fed561c98c7f43680c045651da84835a7d3338e3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636e64727364726d6e2f73686f72742d75726c)](https://github.com/cndrsdrmn/short-url/blob/master/LICENSE)

A lightweight and flexible Laravel package for generating and managing short URLs. This package simplifies the process of creating short links with customizable options, middleware, and bot protection.

---

**Features**
------------

[](#features)

- 📏 **Customizable token formats and lengths**: Choose from mixed, numeric, or alphabetic tokens.
- 🛡 **Bot protection**: Optionally block requests from known bots.
- ⚡ **Quick setup**: Easily integrate into existing Laravel projects.
- 🔒 **Token encryption**: Secure your tokens with a custom encryption callback.
- 🎛 **Middleware support**: Add custom middleware to short URL routes.

---

**Installation**
----------------

[](#installation)

Install the package via Composer:

```
composer require cndrsdrmn/short-url
```

---

**Configuration**
-----------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=short-url-config
```

The configuration file `config/short-url.php` will be published. It includes the following options:

```
return [
    /*
    |--------------------------------------------------------------------------
    | URL Prefix
    |--------------------------------------------------------------------------
    |
    | This value sets the prefix for the short URL routes. It will be used as the
    | base path for accessing the short URLs.
    |
    */
    'prefix' => '/s',

    /*
    |--------------------------------------------------------------------------
    | Allowed Schemas
    |--------------------------------------------------------------------------
    |
    | Specify the schema can be allowed for generated token.
    |
    */
    'allowed_schemas' => [
        'http',
        'https'
    ],

    /*
    |--------------------------------------------------------------------------
    | Database Connection
    |--------------------------------------------------------------------------
    |
    | Specify the database connection to be used for storing short URLs. If null,
    | the default connection defined in the database configuration will be used.
    |
    */
    'connection' => null,

    /*
    |--------------------------------------------------------------------------
    | Middleware
    |--------------------------------------------------------------------------
    |
    | Define the middleware to apply to the short URL routes. By default, the routes
    | are throttled to prevent abuse. You can modify or extend the middleware stack
    | as needed.
    |
    */
    'middleware' => [
        'throttle:100,1',
    ],

    /*
    |--------------------------------------------------------------------------
    | Token Format
    |--------------------------------------------------------------------------
    |
    | Specify the format used to generate tokens for short URLs. Supported values:
    | - "bothify": Mix of letters and numbers (e.g., `A1b2C`)
    | - "numerify": Numbers only (e.g., `12345`)
    | - "lexify": Letters only (e.g., `ABCDE`)
    |
    */
    'token_format' => 'bothify',

    /*
    |--------------------------------------------------------------------------
    | Token Length
    |--------------------------------------------------------------------------
    |
    | Define the length of the token generated for the short URLs. The token's
    | length determines how many characters will be included in the generated URL.
    |
    */
    'token_length' => 5,

    /*
    |--------------------------------------------------------------------------
    | Block Bots
    |--------------------------------------------------------------------------
    |
    | If enabled, requests from known bots will be blocked from accessing the
    | short URLs. This is useful for preventing automated access and ensuring
    | accurate analytics.
    |
    */
    'should_block_bots' => true,
];
```

---

**Usage**
---------

[](#usage)

### **Basic Usage**

[](#basic-usage)

#### Shorten a URL

[](#shorten-a-url)

You can easily generate a short URL with the `ShortUrl` facade:

```
use Cndrsdrmn\ShortUrl\Facades\ShortUrl;

$shortUrl = ShortUrl::shorten('https://example.com');
echo $shortUrl; // Outputs the short URL
```

---

### **Advanced Usage**

[](#advanced-usage)

#### Customizing the Builder

[](#customizing-the-builder)

Customize your short URL with the `make` method:

```
use Cndrsdrmn\ShortUrl\Facades\ShortUrl;

$builder = ShortUrl::make('https://example.com', [
    'is_single_use' => true,
]);

$shortUrl = $builder->create();
echo $shortUrl->accessLink;
```

#### Setting Custom Headers and Queries

[](#setting-custom-headers-and-queries)

```
$builder = ShortUrl::make('https://example.com')
    ->headers(['X-Custom-Header' => 'value'])
    ->queries(['utm_source' => 'newsletter']);

$shortUrl = $builder->create();
echo $shortUrl->accessLink;
```

---

**Routes**
----------

[](#routes)

By default, the package automatically registers a route for handling short URL redirections. If you want to customize the routing:

1. Disable route registration on boot in `App\Providers\AppServiceProvider`: ```
    ShortUrl::ignoreRoutes();
    ```
2. Define your own route in `routes/web.php`: ```
    use App\Http\Controllers\RedirectController;

    Route::get('/s/{token}', [RedirectController::class, 'handle']);
    ```

---

**Security**
------------

[](#security)

### **Encrypt Tokens**

[](#encrypt-tokens)

Set a custom encryption callback to secure your tokens:

```
ShortUrl::encryptTokenUsing(function ($token) {
    return encrypt($token);
});
```

---

**Testing**
-----------

[](#testing)

Run the tests with PHPUnit:

```
php artisan test
```

---

**License**
-----------

[](#license)

This package is open-sourced software licensed under the [MIT license](./LICENSE).

---

**Contributing**
----------------

[](#contributing)

Contributions are welcome! Please see more detail on [CONTRIBUTING.md](./CONTRIBUTING.md).

---

**Credits**
-----------

[](#credits)

- **Author:** [Candra Sudirman](https://github.com/cndrsdrmn)
- **Inspired by:** URL shortening services like Bitly.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance41

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

523d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6241ea6ad620ee6d8fc3d3bac59afcad6c05ad00f4184da528eb44e69236789?d=identicon)[cndrsdrmn](/maintainers/cndrsdrmn)

---

Top Contributors

[![cndrsdrmn](https://avatars.githubusercontent.com/u/19147653?v=4)](https://github.com/cndrsdrmn "cndrsdrmn (3 commits)")

---

Tags

urlphplaravelshort

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/cndrsdrmn-short-url/health.svg)

```
[![Health](https://phpackages.com/badges/cndrsdrmn-short-url/health.svg)](https://phpackages.com/packages/cndrsdrmn-short-url)
```

###  Alternatives

[dusterio/link-preview

Link preview generation for PHP with Laravel support

126326.6k3](/packages/dusterio-link-preview)[shivella/laravel-bitly

Laravel package for generating bitly url

75789.0k1](/packages/shivella-laravel-bitly)[laracrafts/laravel-url-shortener

Powerful URL shortening tools in Laravel

97110.7k](/packages/laracrafts-laravel-url-shortener)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
