Ana Sayfa / Kod ve Scriptler / LinkForge - Self-Hosted URL Shortener

LinkForge - Self-Hosted URL Shortener

Kurallar, parola ve son kullanma koruması, analitik ve bir REST API ile markalı kısa bağlantılar oluşturun.

  • Yayın tarihi10 Kasım 2026
  • Nerede çalışırPHP 8.2, PHP 8.3, PHP 8.4
  • VeritabanıMySQL 8.0, SQLite 3.x
  • Paket içeriği.php, .css, .json, .svg, .sql, .md, .yml/.yaml, composer.json, Dockerfile, JavaScript .js
  • Son güncelleme16 Kasım 2026
  • Canlı demoVar
LinkForge - Self-Hosted URL Shortener

Overview

Branded short links with rules, password and expiry protection, bot-filtered analytics and a REST API. LinkForge is a complete, self-hosted URL Shortener in plain PHP 8.2 — no framework, no Composer runtime dependencies and no build step. Upload the files, run the browser installer, choose SQLite or MySQL, and you are live in minutes.

Short links with analytics you own. Self-hosted URL shortener with branded domains, per-link redirect rules, password/expiry protection, bot-filtered analytics, CSV import/export and a token-authenticated REST API.

What's inside

  • Links — custom or generated slugs, case-insensitive uniqueness, reserved words (install, login, api, assets, admin, …) rejected with a clear error. Title, tags, status, per-link CSV export.
  • Redirects — GET /{slug} resolves in one indexed lookup, evaluates rules, records the click best-effort and returns a 302. The fast path in public/index.php runs before the session, router and view layer.
  • Rules — country (CF-IPCountry / X-Country-Code), device (mobile/desktop/tablet), referrer substring, and A/B split with weights that are sticky per visitor (signed lf_v cookie + link id bucket).
  • Protection — password gate (hashed, signed 15-minute unlock cookie), expiry with a custom fallback destination, and a max-click cap. Disabled, expired or capped links go to the fallback, or 410 Gone when there is none. Those clicks are still recorded with outcome=fallback.
  • Domains — multiple hostnames, each with a default destination for unknown slugs and a verification flag that flips automatically the first time a request arrives through that hostname.
  • Analytics — totals vs unique visitors, bot filtering (HEAD + crawler user-agents), 7/30-day sparkline, top referrers/countries/UTMs/devices and outcomes, per-link click CSV export.
  • CSV — import (file or paste; destination required, existing slugs updated) and export of the full link table.
  • REST API — bearer tokens, JSON only, 401 JSON for a missing or wrong token; create/list/read/delete links.

Why LinkForge

  • Per-link redirect rules: geo (country header), device, referrer and A/B split with sticky assignment.
  • Bot-filtered click analytics: unique vs total, referrer, UTM breakdown, 30-day sparkline.

Built to last

  • No framework and no runtime Composer packages — the ZIP is the whole application.
  • SQLite for a zero-config install and MySQL/MariaDB for production, from one migration pair.
  • 25 automated tests covering the money, state-machine, uniqueness and permission rules.
  • English and Chinese interface, dark mode, WCAG AA focus states, usable down to 360 px.
  • CSRF on every POST, prepared statements only, output escaped at the template.

Requirements

  • PHP 8.2 or newer with PDO (pdo_sqlite or pdo_mysql), mbstring, json, openssl and fileinfo.
  • Apache with mod_rewrite or Nginx; document root pointed at public/.
  • SQLite 3 (bundled with PHP) or MySQL 8 / MariaDB 10.4+.
  • Write access to the application root and storage/.

Quick start: upload the ZIP, point the document root at public/, open /install/ and follow the four steps. Docker users can run docker compose up -d --build instead and open the same installer.

Features

• Links — custom or generated slugs, case-insensitive uniqueness, reserved words (install, login, api, assets, admin, …) rejected with a clear error. Title, tags, status, per-link CSV export. • Redirects — GET /{slug} resolves in one indexed lookup, evaluates rules, records the click best-effort and returns a 302. The fast path in public/index.php runs before the session, router and view layer. • Rules — country (CF-IPCountry / X-Country-Code), device (mobile/desktop/tablet), referrer substring, and A/B split with weights that are sticky per visitor (signed lf_v cookie + link id bucket). • Protection — password gate (hashed, signed 15-minute unlock cookie), expiry with a custom fallback destination, and a max-click cap. Disabled, expired or capped links go to the fallback, or 410 Gone when there is none. Those clicks are still recorded with outcome=fallback. • Domains — multiple hostnames, each with a default destination for unknown slugs and a verification flag that flips automatically the first time a request arrives through that hostname. • Analytics — totals vs unique visitors, bot filtering (HEAD + crawler user-agents), 7/30-day sparkline, top referrers/countries/UTMs/devices and outcomes, per-link click CSV export. • CSV — import (file or paste; destination required, existing slugs updated) and export of the full link table. • REST API — bearer tokens, JSON only, 401 JSON for a missing or wrong token; create/list/read/delete links. • Team — admin and editor roles enforced in controllers and queries. • Self-hosted PHP 8.2 application with no framework and no runtime Composer dependencies • SQLite and MySQL/MariaDB support from one migration pair, with a four-step browser installer • 9 database tables, 44 routes and 25 automated tests • English and Chinese interface, dark mode, WCAG AA focus states, mobile down to 360 px • CSRF protection, prepared statements and escaped output throughout

Requirements

• PHP 8.2 or newer (tested on 8.2, 8.3 and 8.4) • PDO with pdo_sqlite or pdo_mysql • mbstring, json, openssl and fileinfo extensions • Apache with mod_rewrite, or Nginx with a front-controller rule • SQLite 3, or MySQL 8.0 / MariaDB 10.4 and newer • Write access to the application root and storage/ directory • A modern browser; no Node.js, Composer or build tools required