GET /[shortCode]
Resolve a short code and redirect to the original URL. This is the core redirect functionality that makes short links work.
Path Parameters
The short code to resolve. Can be auto-generated (8 characters) or custom (1-20 characters).
- Maximum length: 20 characters
- Reserved codes are blocked:
api, shorten, login, register, dashboard, _next, favicon.ico
- Codes are case-sensitive
The endpoint reads these headers for analytics tracking:
Client IP address for click tracking. First IP in comma-separated list is used.
Alternative client IP header (fallback if X-Forwarded-For is not present).
Browser/client information for analytics.
The referring page URL (also accepts Referrer spelling).
Response
On success, returns an HTTP 307 redirect to the original URL.
The destination URL to redirect to.
HTTP 307 (Temporary Redirect) - preserves request method and body.
Behavior
- Reserved Check: Returns 404 if short code is in reserved list
- Redis Cache: Checks Redis cache first (fastest)
- Database Lookup: If cache miss, queries database:
- Matches
short_code
- Checks expiration (
expires_at > NOW() or NULL)
- Returns null if expired or not found
- Cache Population: Stores result in Redis if found in database
- Analytics: Records click with IP, user agent, and referrer
- Redirect: Returns 307 redirect to original URL
Each redirect increments two metrics:
- Click counter:
urls.clicks column incremented by 1
- Click record: New row in
clicks table with:
- Short code
- IP address (from
X-Forwarded-For or X-Real-IP)
- User agent
- Referrer URL
- Timestamp (automatic)
Click tracking is best-effort and doesn’t block the redirect if it fails.
Error Responses
Returns plain text "Not found" in these cases:
- Short code is reserved
- Short code doesn’t exist in database
- Link has expired
- Short code exceeds 20 characters
Examples
curl -L https://shrtnr.app/Xy9pQz1m
# Redirects to original URL
Success Response
HTTP/1.1 307 Temporary Redirect
Location: https://example.com/original/long/url
Content-Length: 0
Error Response
HTTP/1.1 404 Not Found
Content-Type: text/plain
Not found
Reserved Short Codes
The following short codes cannot be used and will always return 404:
api - API routes
shorten - Shortening interface
login - Authentication
register - User registration
dashboard - User dashboard
_next - Next.js internal routes
favicon.ico - Browser favicon requests
The endpoint uses HTTP 307 (Temporary Redirect) instead of 301 (Permanent) to preserve the HTTP method and allow analytics tracking on each visit.
Short codes are case-sensitive. MyLink, mylink, and MYLINK are three different short codes.
- Redis Cache: First-level cache with TTL matching link expiration
- Cache Key Format:
short:{shortCode}
- Cache Invalidation: Automatic on TTL expiry, manual on update/delete
- Fallback: Database query if cache miss
- Write-Through: Database insert populates cache immediately
This two-tier approach ensures sub-millisecond redirect times for popular links.