Lorixen.
EN

Generating URL slugs from titles: accents, symbols, duplicates

Short answer: A good slug generator turns a title like "Crème Brûlée Kits – 20% Off!" into something like creme-brulee-kits-20-off: normalise the text, strip accents where your language allows, lower-case it, replace anything that isn't a letter or digit with a hyphen, collapse repeated hyphens, trim it to a sensible length and make it unique. Then freeze it. A slug that changes every time someone edits the title breaks links and costs you search visibility unless a redirect is added each time.

Why slug generation deserves five minutes of thought

Most CMS platforms create slugs automatically, and most of the time they're fine. Problems show up on custom-built sites, product catalogues imported from suppliers, and apps that create pages for every location, event or listing:

  • Titles with accents, emoji or symbols produce ugly or broken URLs.
  • Two products with the same name collide, and one silently overwrites the other or errors out.
  • Mixed upper and lower case creates duplicate URLs.
  • A small title edit changes the URL, and every link to the old one breaks.

What Google recommends for URLs

Google's URL structure guidance gives a few rules that a slug generator should follow:

  • Use readable words rather than long ID numbers where possible.
  • Separate words with hyphens, not underscores. Google says hyphens help users and search engines identify concepts in the URL, and recommends against underscores. Joining words together, as in greendress, is also listed as not recommended.
  • Use the audience's language. The guidance shows that non-ASCII words in URLs are acceptable when they're percent-encoded as needed, for example a German or Japanese word.
  • Remember URLs are case sensitive. Google treats /APPLE and /apple as distinct URLs, so a consistent case avoids duplicates.

A reliable slug recipe

Here's a sequence your developer can implement in any language:

  1. Normalise Unicode. Characters like "é" can be stored as one code point or as "e" plus a combining accent. MDN's documentation on String.prototype.normalize() explains these forms: NFC composes characters, NFD decomposes them into base letters and combining marks. Decomposing with NFD (or NFKD, which also simplifies compatibility characters) lets you then remove the combining marks.
  2. Decide on accents. For English-language sites, stripping accents ("crème" to "creme") is usually best. For sites in languages where accents change meaning, keep the letters and let them be percent-encoded, following Google's guidance on using your audience's language.
  3. Transliterate special letters that don't decompose, such as "ß" to "ss", "æ" to "ae" or "ø" to "o", using a library rather than a hand-made list if you support many languages.
  4. Lower-case everything.
  5. Replace symbols. Turn "&" into "and" if you like, drop apostrophes so "Joe's" becomes joes rather than joe-s, and replace every other run of non-alphanumeric characters with a single hyphen.
  6. Trim hyphens from the start and end.
  7. Limit length. Cut at a word boundary around 60 to 80 characters. Long titles make long URLs that get truncated in search results and messages.
  8. Remove stop words carefully, or not at all. Dropping "the" and "a" can shorten slugs, but don't remove words that carry meaning, such as "no" in "no-deposit-booking".
  9. Make it unique. Check the database for an existing slug in the same section; if one exists, add a suffix like -2 or a meaningful qualifier such as the colour or city.

Examples:

Title Slug
Crème Brûlée Kits – 20% Off! creme-brulee-kits-20-off
Joe's Café & Bakery joes-cafe-and-bakery
Winter Boots (Men's) winter-boots-mens
Winter Boots (Men's), second one winter-boots-mens-2

Handle emoji and empty results

Titles made entirely of emoji or symbols can produce an empty slug. Your generator should fall back to something meaningful, such as the item type plus its ID (product-48213), rather than creating a page at the section root or crashing.

Freeze slugs after publishing

The most important rule isn't about characters at all. Once a page is published and indexed, its URL should stay the same:

  • Generate the slug when the item is first created or first published.
  • Don't regenerate it automatically on every title edit.
  • If an editor deliberately changes the slug, store the old one and create a permanent (301) redirect to the new URL.
  • Keep a history table of old slugs so imports and bulk edits can't break links silently.

Many CMS platforms already behave this way for posts; check whether yours does the same for products, categories and custom content types.

Reserved words and collisions with routes

Slugs that match your own routes cause strange bugs. Block slugs like admin, login, cart, checkout, api, search and new in sections where they'd clash with real pages.

Test the generator with awkward titles

Before trusting it with a catalogue, run a list of deliberately difficult titles through it and read the output: titles with quotes and apostrophes, slashes and plus signs, all capitals, very long supplier names, numbers with units like "1/2 inch", titles in two languages, and two items that differ only by punctuation. Keep that list as an automated test, so a future change to the code can't quietly start producing different URLs for existing content.

An illustrative example

A hypothetical Montreal kitchenware shop imported 2,000 products from a supplier feed with French and English names. Its custom importer turned "Poêle en fonte – 28 cm" into po-le-en-fonte-28-cm and gave three identical frying pans the same slug, so only one appeared. The developer switched to NFKD normalisation with accent stripping, added transliteration, appended the size or colour to duplicates, and stopped regenerating slugs on re-import. The broken URLs from the first import were redirected to the corrected ones.

FAQ

Should slugs include IDs?

Only if your platform needs them for uniqueness. Readable words alone are fine when the slug is unique within its section.

Is it bad to keep accents in URLs?

No. Google's guidance shows non-English words in URLs. For an English-language audience, accent-free slugs are simply easier to type and share.

How long should a slug be?

Long enough to describe the page, short enough to read at a glance. Three to six words is typical.

What about uppercase letters?

Use lower case consistently, since URLs are case sensitive.

If your site's URLs come out messy or keep breaking after edits, send us a few examples of titles and their URLs.

Sources

WhatsAppBook a call