URL Lifecycle
Short URLs in the system go through the following states:Active (url_state: true)
URL is live and redirecting traffic. Hit counter increments with each access.
Paused (url_state: false)
URL redirection is temporarily disabled. Returns 423 (Locked) status when accessed.
Only password-protected URLs can be paused, resumed, or deleted. URLs without passwords are permanent.
Creating URLs
Basic URL Creation
With Password Protection
Response
URL Code Validation
URL codes must meet specific validation criteria enforced by thevalidCode function:
helper.py:2-7
Validation Rules
Length Requirements
Length Requirements
- Minimum: 3 characters
- Maximum: 20 characters
helper.py:6
Allowed Characters
Allowed Characters
URL codes can only contain:
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Numbers (0-9)
- Hyphens (-)
- Underscores (_)
my-link, URL_123, short2024Invalid Examples: my link (space), url@code (special char), my.url (period)Reserved Keywords
Reserved Keywords
The following keywords are reserved and cannot be used as URL codes:
docsredoccreatelogindeletepauseresumedetailsrefresh_tokenchange_passwordreset_hitschange_urlvalidate_tokenhealth
Validation Error
Password Protection
Passwords are optional but enable full management capabilities when provided.Password Validation
Passwords must meet the following criteria:helper.py:19-21
- With Password
- Without Password
Requirements:
- Minimum: 3 characters
- Maximum: 20 characters
- Full management control
- Pause/resume functionality
- URL deletion
- Destination URL changes
- Statistics access
Password Hashing
Passwords are hashed using PBKDF2-SHA256 before storage:main.py:85
Password Validation Error
URL State Management
Password-protected URLs can be paused and resumed without deletion.Pausing a URL
Temporarily disable redirection while keeping the URL reserved:main.py:139-147
When paused, accessing the short URL returns a 423 (Locked) error: “Redirect temporarily paused”
Resuming a URL
Re-enable redirection for a paused URL:Paused URL Behavior
When a URL is paused, the redirect endpoint checks the state:main.py:233-239
Hit Counter Tracking
The system automatically tracks how many times each URL is accessed.Automatic Tracking
Hit counters increment asynchronously in the background:main.py:49-51
Hit tracking only occurs for password-protected URLs. Public URLs without passwords do not track hits.
Resetting Hit Counter
Reset the hit counter to zero without affecting other statistics:main.py:159-167
Viewing Hit Statistics
Retrieve hit count and other statistics via the/details endpoint:
Changing Destination URLs
Update where a short URL redirects without changing the URL code:Implementation
main.py:169-179
URL Formatting
The system automatically formats URLs by addinghttps:// if missing:
helper.py:9-13
- Input:
example.com→ Output:https://example.com - Input:
http://example.com→ Output:http://example.com - Input:
https://example.com→ Output:https://example.com
URL Blacklisting
The system supports blacklisting specific URLs to prevent malicious or unwanted destinations.Configuration
Blacklist is configured via theURL_BLACKLIST environment variable:
main.py:17
Blacklist Checking
helper.py:23-27
Where Blacklisting Applies
URL Creation
URL Creation
Blacklisted URLs are rejected during creation:Error Response:
main.py:78-79
URL Changes
URL Changes
Blacklist is also enforced when changing destination URLs:
main.py:174-175
Deleting URLs
Permanently remove a short URL and all associated statistics:Implementation
main.py:127-137
Data Model
URLEntry (URLMap Collection)
models.py:3-6
URLStats Collection
models.py:8-12
Database Structure
- URLMap Collection
- URLStats Collection
Stores the core URL mapping:
| Field | Type | Description |
|---|---|---|
_id | ObjectId | Unique MongoDB identifier |
url_code | string | Short URL code (unique index) |
url_pass | string | Hashed password (empty for public URLs) |
url | string | Destination URL |
URLStats entries are only created for non-empty URLs. The system checks
if len(entry.url)>0 before creating statistics.Common Errors
| Status Code | Error | Cause |
|---|---|---|
| 400 | Invalid URL code | URL code violates validation rules |
| 400 | Password length must be 3..20 | Password outside allowed length |
| 400 | URL Blacklisted | Destination URL matches blacklist |
| 404 | URL not found | URL code doesn’t exist |
| 409 | URL code already exists | Duplicate URL code |
| 423 | Redirect temporarily paused | URL is in paused state |
Best Practices
Choose Meaningful URL Codes
Choose Meaningful URL Codes
- Use descriptive codes:
product-launch-2026instead ofabc123 - Keep them short but memorable
- Avoid easily confused characters if sharing verbally
Use Passwords for Manageable URLs
Use Passwords for Manageable URLs
- Always use passwords for URLs you might need to update
- Public URLs without passwords cannot be modified
- Keep passwords secure - they cannot be recovered
Monitor Hit Statistics
Monitor Hit Statistics
- Use
/detailsto track URL performance - Reset counters when repurposing URLs for new campaigns
- Pause URLs instead of deleting if you might reuse them
Handle Paused States Gracefully
Handle Paused States Gracefully
- Return user-friendly messages for 423 errors
- Use pause for maintenance windows
- Resume URLs as soon as maintenance completes