Starter Kit - Ships with your template. You own it - modify freely.
Overview
The redirect system provides enterprise-grade URL shortening with three link types:- Permanent: Traditional short links that never expire
- Expiring: Time-limited links with automatic cleanup
- Single-use: Magic links for secure one-time access
Quick Start
1. Create a Redirect
2. Use the Short Link
3. Manage Redirects
Ensembles
The redirect system consists of two ensembles:Resolve Ensemble
File:ensembles/system/redirects/resolve.yaml
Handles public redirect resolution at /go/:slug.
- Public access (no authentication)
- Automatic single-use link marking
- Comprehensive error handling
- Low route priority (doesn’t override explicit routes)
API Ensemble
File:ensembles/system/redirects/api.yaml
Provides authenticated CRUD operations at /api/v1/redirects.
- RESTful API design
- Authentication required
- Supports all CRUD operations
- Pagination for list endpoint
- Filter by type, used status, campaign
Agent Reference
redirect Agent
File:agents/system/redirect/redirect.yaml
The core redirect agent that powers both ensembles.
Input Schema
Output Schema
Configuration Schema
Configuration
1. Add KV Binding
Add to yourwrangler.toml:
2. Configure Base Path
The default base path is/go. To customize:
3. Configure Slug Generation
4. Set Default Redirect Type
Examples
Permanent Link
Expiring Link (24 hours)
Single-Use Magic Link
Resolve Without Marking Used
Useful for previewing or analytics:List with Filters
Update Redirect
Delete Redirect
Customization
Change Slug Algorithm
Editagents/system/redirect/redirect.ts:
Add Analytics Tracking
Editagents/system/redirect/redirect.ts in the resolve function:
Add Custom Metadata Fields
Editagents/system/redirect/redirect.yaml:
Custom Error Pages
Editensembles/system/redirects/resolve.yaml:
Add Rate Limiting
Add Webhook Notifications
Common Use Cases
Email Campaign Links
Password Reset Links
QR Code Links
A/B Testing
Best Practices
1. Choose the Right Link Type
- Permanent: Public links, documentation, long-term campaigns
- Expiring: Time-sensitive promotions, temporary access
- Single-use: Magic links, password resets, secure tokens
2. Set Appropriate Expiration Times
3. Use Metadata for Organization
4. Choose Status Codes Wisely
- 301: Permanent redirect (cached by browsers)
- 302: Temporary redirect (default, allows updates)
- 307: Temporary redirect (preserves HTTP method)
- 308: Permanent redirect (preserves HTTP method)
5. Implement Analytics
Track redirect usage:- Click counts
- Geographic distribution
- Device types
- Referrer sources
- Time-based patterns
6. Monitor and Clean Up
- List unused redirects periodically
- Remove expired redirects manually if needed
- Archive old campaign data
- Monitor KV storage usage
7. Secure Custom Slugs
Error Handling
All errors include descriptive messages:Next Steps
Slug Generator
Generate URL-safe slugs
Starter Kit Overview
Explore other starter kit components
KV Storage
Learn about Cloudflare KV
Triggers
Trigger configuration

