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
  • Per-short-URL redirect status (301, 302 or 307), starting from the site default
  • CSV import from a CSV file or a YOURLS export, creating or updating short URLs, from the admin form or Drush
  • 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-store header 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

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) for new short URLs; each short URL keeps its own
  • Destination type (external only, or both internal and external)
  • QR code format (PNG or SVG)
  • Administration theme for short URL pages
  • Visit tracking (enable/disable)
  • Browser cache control (no-store header on redirects)
  • Built-in statistics (store visits in the database, or rely on external analytics only)
  • Visit retention (delete visits older than a number of days on cron)

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 slugs promo
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. The statistics endpoint also requires View any short URL statistics, or View short URL statistics on a short URL the user can view, and the database statistics endpoint requires View any short URL statistics. The expand and QR code endpoints answer 404 for a short URL the user cannot view.

Endpoint Description
GET /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
  • /{slug}.qr — the short URL's own QR code address

The PNG and SVG images open in the browser, where they can be copied or saved.

Documentation and demo

Previous module

This project namespace was previously used by an unrelated Drupal 6/7 module developed 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.

Supporting organizations: 
Development

Project information

Releases