Where I discuss creating a bitly style self-hosted URL shortener written for the Laravel framework.
While working through my funemployment (which wasn’t fun, but maybe I can convince myself) I started a side-project to (re-)learn Laravel. The last time I used Laravel was version 4 or 5 — it’s now v. 12 so there’s been a few changes.
My need to learn combined with my need to be more frugal lately (💸 no paychecks). I’ve been brainstorming methods limiting websites dependencies on databases (which typically incur an increased cost from additional hardware requirements). And given one of my websites lost it’s hosting and used to have YOURLS deployed on it I wanted an alternative I could play around with.
Sidenote: a URL shortener essentially allows a mapping from a site you own (e.g. n3f.co) to a much larger or longer URL. There really isn’t much use for it, but I enjoy the vanity aspect (controlling my own), making short urls as bookmarks, sharing links, and tracking clicks.
The actual implementation was pretty simple. Laravel made creating the routes really easy and I just had to create a couple react components and add them to the default project. I thought this might be a fun project to try with Rails and Go as well if I ever get the time (and I wouldn’t even have to do much to the frontend).
Route::controller(UrlController::class)->group(function () {
Route::post('urls', 'store')->name('urls.store');
Route::patch('urls/{id}', 'edit')->name('urls.edit');
Route::get('urls/{id}/stats', 'stats')->name('urls.stats');
Route::delete('urls/{id}', 'destroy')->name('urls.destroy');
})->middleware(['auth', 'verified', 'throttle:10,1']);
Code language: PHP (php)


Right now the feature set isn’t comprehensive, but you can currently:
- Create a short url
- Define the alias or short code. (Or just use an apparently randomly generated one)
- Set an expiration for a defined url (i.e. after a certain timestamp the redirection to the target will stop working)
- Edit or delete your defined urls
- Currently, I’m preserving all requests, but I need additional analytics processing and UI to surface results.
- Uses any database Laravel supports including SQLite (which is free–this results in roughly 50% savings for me 🤑)
Features I need to add (or would like to):
- search
- stats (other than simple clicks)
- QR code sharing.
- bookmarklets (are these even used any more?)
I’m curious if anyone else would find this project helpful. Would you use a link shortener? If so, what features would you like to see?
