<?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: dada qi</title>
    <description>The latest articles on DEV Community by dada qi (@dada_qi_c70e404eada88b6f4).</description>
    <link>https://dev.to/dada_qi_c70e404eada88b6f4</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4090537%2F1c71ea2f-0c30-44cb-a020-2c268a3ddde9.png</url>
      <title>DEV Community: dada qi</title>
      <link>https://dev.to/dada_qi_c70e404eada88b6f4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dada_qi_c70e404eada88b6f4"/>
    <language>en</language>
    <item>
      <title>URL Slugs: The Boring Detail That Quietly Affects Your SEO, Caching, and Bug Reports</title>
      <dc:creator>dada qi</dc:creator>
      <pubDate>Sun, 23 Aug 2026 07:56:57 +0000</pubDate>
      <link>https://dev.to/dada_qi_c70e404eada88b6f4/url-slugs-the-boring-detail-that-quietly-affects-your-seo-caching-and-bug-reports-23jk</link>
      <guid>https://dev.to/dada_qi_c70e404eada88b6f4/url-slugs-the-boring-detail-that-quietly-affects-your-seo-caching-and-bug-reports-23jk</guid>
      <description>&lt;p&gt;Every web developer ships slugs. Almost nobody thinks about them until one breaks: a duplicate-content SEO problem, a 404 after someone renames a post, or a bug report with a URL full of &lt;code&gt;%E2%80%99&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This post covers what a good slug looks like, the edge cases that break naive implementations, and a copy-paste &lt;code&gt;slugify()&lt;/code&gt; you can actually trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a slug, precisely?
&lt;/h2&gt;

&lt;p&gt;The slug is the human-readable identifier segment of a URL path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/blog/url-slugs-best-practices
                         └───────── slug ─────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It usually derives from a title, but it is &lt;strong&gt;not&lt;/strong&gt; the title. It's an identifier with three jobs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Readable by humans&lt;/strong&gt; — in the address bar, in search results, in a Slack message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stable&lt;/strong&gt; — it's part of a permalink. Links, bookmarks, and search engine indexes depend on it not changing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safe&lt;/strong&gt; — no encoding surprises across browsers, CDNs, log pipelines, and markdown parsers.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The rules that matter
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Lowercase, always
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;/Blog/My-Post&lt;/code&gt; and &lt;code&gt;/blog/my-post&lt;/code&gt; are different URLs to most servers and to Google. Mixed case invites duplicate-content splits and broken links from people retyping URLs. Normalize to lowercase at creation time &lt;em&gt;and&lt;/em&gt; 301-redirect the wrong-case variants.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Hyphens, not underscores
&lt;/h3&gt;

&lt;p&gt;Google has been explicit about this for years: hyphens are word separators, underscores are not. &lt;code&gt;url_slug_guide&lt;/code&gt; reads as one token; &lt;code&gt;url-slug-guide&lt;/code&gt; reads as three words. Hyphens also survive underlining in UI (an underscore under an underlined link is invisible).&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Short, but not cryptic
&lt;/h3&gt;

&lt;p&gt;Aim for 3–6 meaningful words. Strip stop words (&lt;code&gt;a&lt;/code&gt;, &lt;code&gt;the&lt;/code&gt;, &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;of&lt;/code&gt;...) when the slug stays readable without them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Title: &lt;em&gt;"A Complete Guide to the URL Slugs That Google Actually Likes"&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Bad: &lt;code&gt;a-complete-guide-to-the-url-slugs-that-google-actually-likes&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Good: &lt;code&gt;url-slug-guide&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The slug should survive the title being A/B tested. If you tie the slug to the exact title, every headline tweak becomes a redirect decision.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. ASCII-safe by default
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;café&lt;/code&gt; → &lt;code&gt;cafe&lt;/code&gt;, &lt;code&gt;naïve&lt;/code&gt; → &lt;code&gt;naive&lt;/code&gt;. Accented characters &lt;em&gt;work&lt;/em&gt; in modern browsers, but they get percent-encoded the moment they're copied into plain text: &lt;code&gt;caf%C3%A9&lt;/code&gt;. That's ugly in search results and a minefield in log processing and old tooling.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Never change a published slug (without a 301)
&lt;/h3&gt;

&lt;p&gt;A slug is a contract. If you must rename, keep a redirect from the old slug forever. WordPress does this automatically; if you're rolling your own CMS, store historical slugs in a table and check it on 404.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where naive implementations die
&lt;/h2&gt;

&lt;p&gt;The classic Stack Overflow one-liner handles English and nothing else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ⚠️ the naive version&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;slugify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[^&lt;/span&gt;&lt;span class="sr"&gt;a-z0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^-+|-+$/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Feed it real-world input and watch:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;Naive output&lt;/th&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Beyoncé's Résumé&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;beyonc-s-r-sum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Accents deleted, not transliterated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C++ vs C# in 2026&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;c-vs-c-in-2026&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Meaning destroyed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;你好世界&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;em&gt;(empty string)&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;CJK wiped out entirely&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;100% 🔥 tips&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;100-tips&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fine — but did you &lt;em&gt;decide&lt;/em&gt; that, or did it just happen?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Fixes, in order of effort:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transliterate before stripping.&lt;/strong&gt; &lt;code&gt;String.prototype.normalize("NFKD")&lt;/code&gt; decomposes accented characters into base + combining marks, which you can then remove:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;slugify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;s&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NFKD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                   &lt;span class="c1"&gt;// é → e + ́&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[\u&lt;/span&gt;&lt;span class="sr"&gt;0300-&lt;/span&gt;&lt;span class="se"&gt;\u&lt;/span&gt;&lt;span class="sr"&gt;036f&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;// strip combining marks&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[^&lt;/span&gt;&lt;span class="sr"&gt;a-z0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^-+|-+$/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;slugify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Beyoncé's Résumé&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "beyonce-s-resume"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handle domain terms with a replacement map&lt;/strong&gt; before the generic pass: &lt;code&gt;{"c++": "cpp", "c#": "csharp", "&amp;amp;": "and"}&lt;/code&gt;. No amount of Unicode cleverness knows that &lt;code&gt;C#&lt;/code&gt; is &lt;code&gt;csharp&lt;/code&gt; — that's product knowledge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decide your CJK policy explicitly.&lt;/strong&gt; Three legitimate options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Keep the script&lt;/strong&gt; — &lt;code&gt;/blog/你好世界&lt;/code&gt; is valid and Google indexes it fine; it just percent-encodes when copied (&lt;code&gt;%E4%BD%A0%E5%A5%BD...&lt;/code&gt;). Right choice for a zh/ja/ko-audience site.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transliterate&lt;/strong&gt; — pinyin/romaji via a library (&lt;code&gt;pinyin&lt;/code&gt;, &lt;code&gt;kuroshiro&lt;/code&gt;). Readable ASCII, but lossy and adds a dependency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fall back to an ID&lt;/strong&gt; — &lt;code&gt;/blog/post-8843&lt;/code&gt; when the slug would come out empty. Boring and bulletproof.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The bug isn't picking the "wrong" option — it's not picking one and shipping whatever the regex happens to do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enforce uniqueness at the database.&lt;/strong&gt; Two posts titled "Weekly Update" → same slug. Append &lt;code&gt;-2&lt;/code&gt;, &lt;code&gt;-3&lt;/code&gt; on collision, and put a unique index on the column so a race condition can't sneak duplicates past you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick sanity checks
&lt;/h2&gt;

&lt;p&gt;Before shipping a slug scheme, paste a few real titles from your content backlog through it — especially ones with apostrophes, ampersands, and non-English words. For one-off checks (a landing page, a campaign URL, a colleague's draft) I keep &lt;a href="https://sluggenerator.app" rel="noopener noreferrer"&gt;SlugGenerator.app&lt;/a&gt; in my bookmarks — paste text, get the slug, no install.&lt;/p&gt;

&lt;p&gt;For the pipeline itself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;code&gt;My Post!!!&lt;/code&gt; and &lt;code&gt;my post&lt;/code&gt; produce the same slug (idempotent normalization)&lt;/li&gt;
&lt;li&gt;✅ Empty-after-stripping input falls back to something (ID, date) instead of &lt;code&gt;""&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;✅ Changing a title does &lt;strong&gt;not&lt;/strong&gt; silently change the slug of a published post&lt;/li&gt;
&lt;li&gt;✅ Old slugs 301 to new ones&lt;/li&gt;
&lt;li&gt;✅ Unique index on the slug column&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Lowercase + hyphens + ASCII, 3–6 words, stop words dropped&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;normalize("NFKD")&lt;/code&gt; for accents, replacement map for domain terms, explicit CJK policy&lt;/li&gt;
&lt;li&gt;Slugs are permalinks: never mutate without a 301, enforce uniqueness in the DB&lt;/li&gt;
&lt;li&gt;Test with your ugliest real titles, not &lt;code&gt;"Hello World"&lt;/code&gt; — or throw them at &lt;a href="https://sluggenerator.app" rel="noopener noreferrer"&gt;SlugGenerator.app&lt;/a&gt; and eyeball the output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What's the worst slug bug you've shipped? Mine involved an emoji, a CDN, and a very confused cache key.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>seo</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
