shorturl
Security covered
A URL shortener for Drupal built on node entities, with QR code generation, visit tracking, statistics, and a REST API.
Features
- Short URL content type with three slug modes: custom vanity slugs, random base36 slugs, or sequential auto-increment slugs
- Automatic redirects via the Redirect module — redirects are created and synchronized when short URLs are saved or deleted
- QR code generation (PNG and SVG) using endroid/qr-code, accessible via
/api/shorturl/qr/{slug}endpoints - Visit tracking via a lightweight HTTP middleware that records visits without bootstrapping Drupal on cached requests
- Statistics dashboard on each short URL node with traffic charts, referrer analysis, and country-of-origin mapping
- REST API for programmatic URL expansion and statistics retrieval
- Views integration with a pre-configured admin listing
- Granular permissions for slug modes, statistics viewing, API access, and administration
- Browser cache control with an optional
no-storeheader on redirects for accurate visit counting - Multi-language support — per-translation redirects with language-neutral fallbacks
- Optional country detection via the Smart IP module
- Multi-domain support via the separate Domain Short URL module (requires the Domain module)
Requirements
- Drupal 10.2 or 11.x
- Redirect module (^1)
- endroid/qr-code (^5 || ^6)
Installation
composer require drupal/shorturl drush en shorturl
Configuration
Navigate to Administration > Configuration > Short URL settings (/admin/config/shorturl/settings) to configure:
- Base36 slug length (4–12 characters)
- Default redirect status code (301, 302, or 307)
- Destination type (external only, or both internal and external)
- QR code format (PNG or SVG)
- Visit tracking (enable/disable)
- Browser cache control (no-store header on redirects)
Slug modes
Each short URL uses one of three slug modes, controlled per-node and restricted by permissions:
Mode Permission Example Custom Use custom short URL slugspromo
Base36
Use base36 short URL slugs
k9m2x7
Auto-increment
Use auto-increment short URL slugs
42
REST API
All API endpoints require the Access Short URL API permission.
Endpoint DescriptionGET /api/shorturl/expand/{slug}
Expand a slug to its destination URL
GET /api/shorturl/stats/{nid}
Visit statistics for a short URL
GET /api/shorturl/db-stats
Aggregate database statistics
QR codes
QR code images are available at:
/api/shorturl/qr/{slug}— default format (configured in settings)/api/shorturl/qr/{slug}/png— PNG format/api/shorturl/qr/{slug}/svg— SVG format
Documentation
Full documentation is available at the project documentation site.
Previous module
This project namespace was previously used by an unrelated Drupal 6/7 module developped by the Phase2 Technology company. The original code is still available in the 6.x-1.x branch. The original project was not covered by the Security Advisory Policy.