URL Slugs: SEO-FriendlyNaming Best Practices

The words in your URLs affect click-through rates and search rankings. From hyphens-vs-underscores to 301 redirects — everything you need to create clean, effective URL slugs.

What a URL Slug Does

A slug is the human-readable segment of a URL that identifies a specific resource. In /blog/how-to-build-a-rest-api, the slug is how-to-build-a-rest-api. It's derived from the page title — "How to Build a REST API" — by converting to lowercase, replacing spaces with hyphens, and stripping special characters. A slug serves two audiences. For users, it previews what the page is about before they click — a clean, descriptive URL inspires more trust and click-throughs than /post?id=12345. For search engines, each word in the slug is an additional relevance signal that reinforces the page's title tag and H1 heading.

Auto-generated numeric IDs (/post/12345) tell neither humans nor search engines anything about the content. They're simpler to implement — every CMS supports them out of the box — but they miss the opportunity to add keywords to the URL. A slug like understanding-dns-records contains three keywords that tell Google (and users) exactly what the page covers before anyone reads a word of the content.

Rules for Good Slugs

  • Lowercase only. URLs are case-sensitive on Linux/Unix servers. /About and /about can be different pages — or one can return 404 while the other works. This creates duplicate content problems for search engines and broken links for users. Force lowercase everywhere.
  • Hyphens, not underscores. Google's algorithms treat hyphens as word separators and underscores as word joiners. This was confirmed by Matt Cutts (former head of Google's webspam team) and verified repeatedly since. how-to-build is indexed as three separate words: "how", "to", "build". how_to_build is indexed as one compound word: "how_to_build". If you want your URL keywords to match search queries, use hyphens.
  • Remove stop words. Articles (a, an, the), conjunctions (and, or, but), and prepositions (in, on, at, by, for) add length without meaning in URLs. "How to Build a REST API" should become build-rest-api, not how-to-build-a-rest-api. Exception: keep stop words when removing them changes meaning — "to-be-or-not-to-be" is a specific reference that would lose meaning if reduced to "be-or-not-be".
  • Keep it short. Aim for 3-5 words, under 60 characters. Google truncates long URLs in search results at around 60-70 characters. Longer URLs are harder to share, harder to type, and more likely to be truncated in analytics reports or social media embeds. Each additional word dilutes the keyword density and adds visual noise.
  • No special characters. Strip everything except lowercase letters, numbers, and hyphens. Accented characters should be transliterated: café → cafe, naïve → naive, façade → facade. Unicode characters in URLs get percent-encoded, turning a readable slug into an unreadable string of %C3%A9 sequences. Always output ASCII.
  • Avoid dates. /blog/2024-01-15/how-to-build-an-api signals to users (and search engines) that the content is from January 2024. Two years later, the information might still be accurate, but the URL makes it look outdated. Use /blog/how-to-build-an-api for evergreen content. If dates are needed for URL uniqueness, put them in a separate path segment or use your CMS's date-based archive without putting dates in individual post slugs.

Slug Generation: Manual vs. Automatic

Most CMS platforms auto-generate slugs from the title. WordPress, for example, takes "How to Build a REST API" and produces how-to-build-a-rest-api. This works, but it's unoptimized — the auto-generated slug includes stop words ("how", "to", "a") that add length without keyword value. Always review and edit auto-generated slugs before publishing. Strip the stop words, check the length, and make sure the remaining keywords match what users would actually search for.

Our Slug Generator produces clean slugs from any input text. It handles lowercase conversion, hyphen replacement, stop word removal, Unicode transliteration, and length limits — the things a naive .toLowerCase().replace(/ /g, '-') misses.

Slugs and SEO: What Actually Matters

Keywords in the URL are a minor ranking factor compared to the title tag (major), H1 heading (major), body content (major), and backlinks (major). Changing your slugs to include keywords won't move you from page three to page one. But clean, readable URLs contribute to the overall relevance signal, and they affect click-through rates from search results — a ranking factor Google does track. A user choosing between two search results is more likely to click /blog/how-to-build-a-rest-api than /blog/12345 or /blog/how_to_build_a_rest_api.

When you change a slug, always set up a 301 (permanent) redirect from the old URL to the new one. Without it, anyone who bookmarked or linked to the old URL hits a 404, and Google loses the accumulated PageRank for that page. If you're migrating a site with hundreds or thousands of pages, generate redirect rules programmatically — a URL mapping spreadsheet plus a script to produce server config or .htaccess rules. Test the redirects before deploying. A single misconfigured redirect that creates a loop or points to the wrong page will cause more SEO damage than keeping the old slugs.

Slug Patterns by Content Type

Content TypeURL PatternExample
Blog post/blog/{slug}/blog/dns-records-explained
Product page/products/{slug}/products/wireless-headphones
Category/{slug} or /category/{slug}/audio-equipment
Documentation/docs/{section}/{slug}/docs/api/authentication

Pick a URL structure and commit to it. Changing URL patterns later — moving from /blog/{slug} to /articles/{slug} — requires 301 redirects for every affected URL. For a site with 500 blog posts, that's 500 redirects. Consistent patterns also make your site easier to crawl: Googlebot can discover new pages by incrementing known URL patterns.

Quick Reference

RuleDoDont
Casemy-pageMy-Page
Separatormy-pagemy_page
Special charscafecaf%C3%A9

Handling Slug Conflicts

When two pages would share the same slug, you need disambiguation. Common approaches: numeric suffixes (my-post-2), date prefixes (2024-01-my-post), or category segments (tech/my-post). WordPress uses numeric suffixes. Apply your strategy consistently, and check for conflicts before publishing. A duplicate slug that silently overwrites an existing page is a content management bug that can go unnoticed for months.

Migrating URL Structures

Changing your URL structure — from /blog/2024/01/post-title to /blog/post-title, for example — requires planning. Export all current URLs (from your sitemap, CMS, or server logs). For each old URL, determine the new URL. Generate 301 redirects for every mapping. Test the redirects: both that they redirect to the correct destination and that they do not create redirect chains (A → B → C). Redirect chains slow page loads and can cause search engines to stop following the chain. Each redirect should point directly to the final destination.

After deploying redirects, monitor your search console for 404 errors. A sitemap update tells search engines about your new URLs; the 301 redirects tell them where the old ones went. Both are needed. Expect a temporary dip in search traffic during the transition as Google reindexes your pages. Traffic typically recovers within 2-4 weeks if the redirects are correct. If traffic does not recover, check for redirects pointing to the wrong destinations — a common mistake when generating redirect rules programmatically.