Overview
shrtnr converts long URLs into compact, shareable short links that redirect to your original destination. Every short link is automatically validated, stored securely, and cached for fast redirects.How URL Shortening Works
Paste your URL
Enter any valid HTTP or HTTPS URL into the input field on the home page. shrtnr validates that your URL has a proper protocol and format.
Generate short code
shrtnr generates an 8-character unique identifier using nanoid. This creates billions of possible combinations to ensure uniqueness.
Store and cache
The URL mapping is stored in the database and cached in Redis for lightning-fast lookups. Your short link is ready to use immediately.
Creating a Short Link
For Guest Users
Anyone can create a short link without signing in:- Navigate to the home page
- Paste your long URL in the input field
- Click Shorten
- Your short link is automatically copied to your clipboard
Guest links expire after 7 days by default and cannot be customized or managed after creation.
For Authenticated Users
Signed-in users get additional control:- Paste your URL on the home page
- Optionally set a custom slug (see Custom Slugs)
- Set expiration from 1 to 30 days (defaults to 7 days)
- Click Shorten
- View and manage your link in the Dashboard
URL Validation
shrtnr ensures all URLs are valid before creating short links:- Protocol check: Only
http://andhttps://protocols are allowed - Format validation: URLs must be properly formatted and parseable
- Trimming: Whitespace is automatically removed from both ends
Invalid URLs return an error message: “Invalid URL”. Make sure your URL starts with
http:// or https://.Short Code Generation
The automatic short code generation uses industry-standard nanoid:- Length: 8 characters
- Character set: URL-safe characters (a-z, A-Z, 0-9,
-,_) - Collision resistance: With 8 characters, nanoid provides ~151 years of continuous generation before reaching 1% collision probability at 1000 IDs per hour
Link Expiration
All short links have an expiration date to keep the database clean and respect privacy:- Default expiration: 7 days from creation
- Minimum: 1 day
- Maximum: 30 days
- Automatic cleanup: Expired links return a 404 error and won’t redirect
Expiration dates can be modified after creation in the dashboard. See Link Expiration for details.
Redirect Behavior
When someone visits your short link:- shrtnr checks if the short code exists (reserved routes like
/api,/dashboardreturn 404) - Looks up the original URL in Redis cache for instant response
- If not cached, queries the database and validates the link hasn’t expired
- Records the click with analytics data (IP, user agent, referrer)
- Issues a 307 Temporary Redirect to the original URL
shrtnr uses a 307 redirect instead of 301 to preserve the HTTP method, though most browsers treat GET redirects identically.
Performance & Caching
Redis Caching
Every short link is cached in Redis with automatic TTL (time to live):- Cache key format:
short:{shortCode} - TTL matches the link’s expiration time
- Cache invalidated when links are updated or deleted
Fast Lookups
The two-tier lookup system ensures maximum performance:- Redis check (microseconds): Check in-memory cache first
- Database query (milliseconds): Fallback to database if cache miss
- Cache warming: Database results automatically populate Redis
Error Handling
Common errors and their meanings:| Error | Reason | Solution |
|---|---|---|
| ”Invalid URL” | URL doesn’t have http/https or is malformed | Check your URL starts with http:// or https:// |
| ”Slug already in use” | Custom slug is taken | Choose a different custom slug |
| ”Sign in to use a custom slug” | Tried to use custom slug as guest | Create an account or sign in |
| 404 on redirect | Link expired or doesn’t exist | Verify the short code is correct |
Best Practices
URL Shortening Tips
- Test your original URL works before shortening
- Use custom slugs for branded, memorable links
- Set longer expiration times for links you’ll use repeatedly
- Track link performance in your dashboard
- Delete links you no longer need to keep your dashboard organized
Related Features
- Custom Slugs - Create branded, memorable short links
- Link Expiration - Manage when your links expire
- Analytics - Track clicks and performance
- Dashboard - Manage all your short links in one place