A Laravel-based URL shortener service that converts long URLs into short, shareable links with analytics, custom aliases, expiration, password protection, and QR code generation.
- Shorten Long URLs — Converts any valid long URL into a short, unique URL.
- Custom Aliases — Users can choose their own short code (e.g.,
/my-link). - URL Expiration — Set optional expiration dates for short URLs.
- Password Protection — Protect short URLs with a password.
- Click Analytics — Tracks IP, user agent, referrer, and timestamp for every click.
- QR Code Generation — Generates QR codes for any short URL.
- Bulk Shortening API — Shorten up to 10 URLs in a single API request.
- Rate Limiting — Prevents abuse with throttling on the web form.
- Security Headers — X-Frame-Options, HSTS, CSP, and more.
- Responsive UI — Tailwind CSS with AJAX form submission, copy button, and loading states.
-
short_urls: Stores URL mappingsid— Auto-incrementing primary keyoriginal_url— The original long URL (TEXT)short_code— Auto-generated 6-character codealias— Optional custom alias (unique, nullable)password— Optional hashed password (nullable)expires_at— Optional expiration timestamp (nullable)timestamps— Creation and update times
-
clicks: Stores click analyticsid— Auto-incrementing primary keyshort_url_id— Foreign key to short_urlsip_address— Visitor IP addressuser_agent— Browser user agentreferrer— HTTP referrercountry— Country code (nullable)clicked_at— Timestamp of the clicktimestamps
- Uniqueness: Ensures short URLs and aliases are unique.
- Validation: Validates input URLs, aliases, and expiration dates.
- Caching: Redirect lookups are cached for performance.
git clone https://github.com/VOID-ALIF/url-shortener.git
cd url-shortenercomposer installcp .env.example .env
php artisan key:generateUpdate the database settings in .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=url_shortener
DB_USERNAME=root
DB_PASSWORD=yourpasswordphp artisan migratephp artisan serveThe app will be accessible at http://127.0.0.1:8000.
- Open the application in your browser at
http://127.0.0.1:8000. - Enter a valid long URL in the input field.
- Optionally set a custom alias, expiration date, or password.
- Click Shorten URL.
- Copy the short URL or download the QR code.
All API endpoints require an X-API-Key header.
- Method:
POST - Endpoint:
/api/shorten - Headers:
X-API-Key: your-api-key - Payload:
{ "url": "https://example.com/very-long-url", "alias": "my-link", "expires_at": "2026-09-01T12:00", "password": "secret123" } - Response:
{ "short_url": "http://127.0.0.1:8000/my-link" }
- Method:
POST - Endpoint:
/api/shorten/bulk - Headers:
X-API-Key: your-api-key - Payload:
{ "urls": [ "https://example1.com", "https://example2.com" ] } - Response:
{ "data": [ {"original_url": "https://example1.com", "short_url": "http://127.0.0.1:8000/abc123"}, {"original_url": "https://example2.com", "short_url": "http://127.0.0.1:8000/def456"} ] }
- Method:
GET - Endpoint:
/{code} - Redirects to the original long URL (410 if expired)
- Method:
GET - Endpoint:
/qr/{code} - Redirects to a generated QR code image
php artisan testThis project is licensed under the MIT license.