<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dody Bayu Artaputra</title>
    <description>The latest articles on DEV Community by Dody Bayu Artaputra (@dody_bayuartaputra_37176).</description>
    <link>https://dev.to/dody_bayuartaputra_37176</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3662295%2Fd1695618-4241-44c9-83fb-660e1d82564a.png</url>
      <title>DEV Community: Dody Bayu Artaputra</title>
      <link>https://dev.to/dody_bayuartaputra_37176</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dody_bayuartaputra_37176"/>
    <language>en</language>
    <item>
      <title>Short URLs Without the Struggle</title>
      <dc:creator>Dody Bayu Artaputra</dc:creator>
      <pubDate>Tue, 16 Dec 2025 05:55:17 +0000</pubDate>
      <link>https://dev.to/dody_bayuartaputra_37176/short-urls-without-the-struggle-4905</link>
      <guid>https://dev.to/dody_bayuartaputra_37176/short-urls-without-the-struggle-4905</guid>
      <description>&lt;p&gt;Most URL shortener projects look simple from the outside, but feel surprisingly heavy once you try to deploy them.&lt;/p&gt;

&lt;p&gt;Databases. Migrations. Environment variables. Admin dashboards. For many use cases, that’s a lot of complexity just to turn a long URL into a short one.&lt;/p&gt;

&lt;p&gt;In this post, you’ll see a different approach: a &lt;strong&gt;single-file PHP URL shortener&lt;/strong&gt; that you can drop into a folder like &lt;code&gt;/u&lt;/code&gt;, visit &lt;code&gt;https://yourhost.com/u&lt;/code&gt;, and start using almost immediately.&lt;/p&gt;




&lt;h2&gt;
  
  
  The usual problem with self-hosted short URLs
&lt;/h2&gt;

&lt;p&gt;If you search “url shortener” on GitHub, you’ll find everything from tiny scripts to full-blown platforms with APIs, analytics dashboards, and user accounts.  &lt;/p&gt;

&lt;p&gt;Those are great when you need an entire product. But if you just want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Short URLs on your own domain
&lt;/li&gt;
&lt;li&gt;A light script you understand
&lt;/li&gt;
&lt;li&gt;Something you can easily move between servers
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then a big framework-based app can feel like overkill.&lt;/p&gt;

&lt;p&gt;Common pain points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires setting up a full database and importing schema
&lt;/li&gt;
&lt;li&gt;Bundled with UI/UX and features you don’t need right now
&lt;/li&gt;
&lt;li&gt;Hard to customize because there are too many moving parts
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the other extreme, super-minimal scripts often skip modern needs like &lt;strong&gt;QR codes&lt;/strong&gt; or even the possibility of basic &lt;strong&gt;click stats&lt;/strong&gt;, so you end up bolting on extra tools anyway.&lt;/p&gt;




&lt;h2&gt;
  
  
  A different approach: single-file PHP
&lt;/h2&gt;

&lt;p&gt;The idea behind this project is simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What if URL shortening was just one &lt;code&gt;index.php&lt;/code&gt; file you drop into a folder and it works?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s exactly what the repository &lt;a href="https://github.com/DodyBayuAp/url-shortener" rel="noopener noreferrer"&gt;&lt;code&gt;DodyBayuAp/url-shortener&lt;/code&gt;&lt;/a&gt; aims to provide:&lt;br&gt;&lt;br&gt;
a &lt;strong&gt;URL shortener in a single PHP file&lt;/strong&gt;, licensed under MIT and designed to be easy to self-host.&lt;/p&gt;

&lt;p&gt;Core goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single file&lt;/strong&gt; – all logic inside &lt;code&gt;index.php&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No heavy setup&lt;/strong&gt; – no installer, no extra CLI steps
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Self-hosted&lt;/strong&gt; – runs on your own domain, under any public folder that supports PHP
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customizable&lt;/strong&gt; – you can open the file and actually understand what’s going on
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because it’s just PHP, it works on most shared hosting environments where PHP is already enabled, similar to many older but still popular PHP scripts.&lt;/p&gt;




&lt;h2&gt;
  
  
  How deployment works (step by step)
&lt;/h2&gt;

&lt;p&gt;The deployment flow is intentionally short so that it fits typical dev and “semi-technical” workflows.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Download the file
&lt;/h3&gt;

&lt;p&gt;Grab &lt;code&gt;index.php&lt;/code&gt; from the GitHub repository and save it locally.  &lt;/p&gt;

&lt;p&gt;You don’t need Composer or a framework scaffold. If your server can run regular PHP files, you’re good.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create a &lt;code&gt;/u&lt;/code&gt; folder in your public root
&lt;/h3&gt;

&lt;p&gt;Go to your public web root. Depending on your stack, that might be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;public_html/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;www/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;htdocs/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;public/&lt;/code&gt; (e.g., in a Laravel app)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create a new folder, for example:&lt;/p&gt;

&lt;p&gt;./public/u&lt;/p&gt;

&lt;p&gt;This folder will act as the “gateway” for all your short URLs.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Drop &lt;code&gt;index.php&lt;/code&gt; inside that folder
&lt;/h3&gt;

&lt;p&gt;Move the &lt;code&gt;index.php&lt;/code&gt; file into your &lt;code&gt;u&lt;/code&gt; folder:&lt;/p&gt;

&lt;p&gt;public/&lt;br&gt;
u/&lt;br&gt;
index.php&lt;/p&gt;

&lt;p&gt;At this point, any request to &lt;code&gt;/u&lt;/code&gt; will be handled by that single PHP file.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Access &lt;code&gt;https://yourhost.com/u&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Open your browser and visit:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://yourhost.com/u" rel="noopener noreferrer"&gt;https://yourhost.com/u&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Replace &lt;code&gt;yourhost.com&lt;/code&gt; with your actual domain (or &lt;code&gt;http://localhost/u&lt;/code&gt; while testing). If PHP is correctly configured, your shortener UI or endpoint should load without additional setup.&lt;/p&gt;

&lt;p&gt;No database migration. No &lt;code&gt;.env&lt;/code&gt; wiring. No extra scaffolding. Just upload and go.&lt;/p&gt;




&lt;h2&gt;
  
  
  Where QR codes, mobile, and analytics fit in
&lt;/h2&gt;

&lt;p&gt;Even though this project is intentionally small, you’re not locked out of modern features.&lt;/p&gt;

&lt;p&gt;Here are three natural extensions:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. QR codes
&lt;/h3&gt;

&lt;p&gt;You can hook in a QR library or external API so each short link gets a corresponding QR code, which is especially useful for print materials and offline campaigns.&lt;/p&gt;

&lt;p&gt;Typical flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create short URL
&lt;/li&gt;
&lt;li&gt;Generate QR code for that short URL
&lt;/li&gt;
&lt;li&gt;Display or download it from the same UI or an extra route&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because everything is inside one file, you only need to wire this feature in a single place instead of multiple controllers/services.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Mobile-friendly UI
&lt;/h3&gt;

&lt;p&gt;No front-end framework is required. A simple HTML layout plus a bit of responsive CSS is enough to make the interface comfortable on mobile.  &lt;/p&gt;

&lt;p&gt;If you’re using this in your own stack, you can even wrap &lt;code&gt;/u&lt;/code&gt; inside your existing styling to keep everything on-brand.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Basic click analytics
&lt;/h3&gt;

&lt;p&gt;On each redirect, you can log things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Timestamp
&lt;/li&gt;
&lt;li&gt;Referer
&lt;/li&gt;
&lt;li&gt;User agent
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even a basic log file or tiny database table will give you useful insights into which short links and campaigns are working.  &lt;/p&gt;

&lt;p&gt;Because this is self-hosted, &lt;strong&gt;you own the data&lt;/strong&gt;, which is a big deal compared to many third-party URL shortener services.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why a single-file URL shortener is still relevant
&lt;/h2&gt;

&lt;p&gt;In a world of microservices, containers, and “platforms”, a single PHP file can feel almost nostalgic.&lt;/p&gt;

&lt;p&gt;But it has real, practical advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Low friction&lt;/strong&gt; – You can add it to almost any existing PHP-capable environment.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy to migrate&lt;/strong&gt; – Moving your shortener to another host is just copying one file.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auditable&lt;/strong&gt; – You can read the entire logic in one place and know what happens to your URLs.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For indie devs, small teams, or solo creators, that trade-off makes sense: fewer dependencies, fewer surprises, less overhead.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try it, tweak it, and star it ⭐
&lt;/h2&gt;

&lt;p&gt;If you want to host short URLs on your own domain without wrestling with a heavy stack, this kind of single-file PHP shortener is a nice middle ground between “too simple” and “too complex”.&lt;/p&gt;

&lt;p&gt;You get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your own domain for short links
&lt;/li&gt;
&lt;li&gt;Source code you can inspect and modify
&lt;/li&gt;
&lt;li&gt;A deployment story that fits into a single README section
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check out the project here:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;GitHub repo:&lt;/strong&gt; &lt;a href="https://github.com/DodyBayuAp/url-shortener" rel="noopener noreferrer"&gt;https://github.com/DodyBayuAp/url-shortener&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you find it useful, &lt;strong&gt;don’t forget to leave a star&lt;/strong&gt; on the repository — it’s a small gesture that really helps open-source projects stand out in a crowded GitHub search result page.&lt;/p&gt;

</description>
      <category>php</category>
      <category>tooling</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
