Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 36 · On-Page SEO

SEO-Friendly URLs and Slugs

Learn how to write clean, readable URLs and slugs: structure, length, hyphens, case, parameters, stop words, changing URLs safely, with a slugify tool and URL auditor.

A URL is the address of a page, and it is also a small piece of content. People see it in results, in the address bar and when they share a link. Search engines use it to find the page, and sometimes as a hint about its topic. A clean URL is short, readable and stable.

This lesson focuses on the URL of a single page, especially its slug: the last human-readable part. For the larger picture of how pages relate in a site, see Site Architecture and URLs.

Parts of a URL

Text
https://www.example.com/guides/repot-tomato-plant?ref=newsletter#steps
\___/   \_____________/\_____________________/ \____________/ \____/
scheme       host              path               query      fragment
  • Scheme: use https.
  • Host: the domain and optional subdomain.
  • Path: folders and the slug (repot-tomato-plant).
  • Query: parameters after ?.
  • Fragment: the part after #, handled by the browser; it points to a section within the page and is not sent to the server.

Best practices

  1. Readable words. /guides/repot-tomato-plant beats /p?id=48213. A human should predict the content from the URL.
  2. Lowercase. URLs may be case-sensitive on the server, so /Guide and /guide can be different pages. Standardize on lowercase.
  3. Hyphens between words, not underscores or spaces. Hyphens are read as word separators.
  4. Short and focused: the primary topic and little else. Very long URLs get truncated in results and are harder to share.
  5. No unnecessary words: drop "the", "a", dates (unless the date is essential), and file extensions such as .php.
  6. Logical folders that reflect your structure (/shop/plants/tomatoes), but keep depth modest.
  7. Avoid parameters for indexable content. Sorting, filtering and tracking parameters create many URLs for the same content (see below).
  8. Avoid special characters: spaces (%20), accents and symbols. Convert them to plain letters or hyphens when your audience can read the result, or use the local script deliberately if the whole site is in that language.
  9. Be stable. A URL should not change unless it has to.
  10. One version per page: choose www or not, trailing slash or not, and redirect the others to it.

Try it: a slugify function

Most content systems generate slugs from titles. The function below lowercases, removes accents, replaces non-alphanumeric runs with hyphens, drops common stop words and limits length. Try your own titles.

Python Slugify page titles

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last title shows why limiting length matters: the full sentence would make an unwieldy URL. Always read the result; automated slugs sometimes drop a word that carries meaning.

Parameters and duplicate URLs

Parameters are fine for features such as search and filters, but each combination creates another URL that may show the same or similar content: /shop?sort=price, /shop?sort=price&color=red. If crawlers explore all of them, they waste crawl budget and spread signals. Common fixes:

  • Point duplicates at the preferred URL with a canonical link (<link rel="canonical" href="...">).
  • Keep filter combinations that people really search for as clean, indexable pages (for example /shop/red-tomato-pots), and keep the rest out of the index.
  • Never put session IDs in URLs.
  • Tag campaigns with parameters, but make sure the page's canonical points at the clean version.

Try it: audit a list of URLs

This program checks URLs against the guidelines above and prints the problems. The thresholds are teaching defaults.

Python URL auditor

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Changing URLs safely

Changing a URL means the old address stops working unless you handle it. Do it only when there is a real reason (a mistake, a restructure, a rebrand). When you must:

  1. Redirect the old URL to the new one with a permanent (301 or 308) redirect, one hop, never a chain.
  2. Update internal links to the new URL, and update sitemaps and canonical tags.
  3. Check that the redirect works and that the old URL no longer appears in the sitemap.
  4. Keep redirects for as long as practical (at least a year; ideally permanently for pages with links).
  5. Monitor crawl errors and rankings afterwards.
flowchart LR
    O["/old-guide"] -->|"301 permanent redirect"| N["/guides/repot-tomato-plant"]
    L["Internal links"] -->|"update directly to"| N
    S["Sitemap"] -->|"list only"| N

Redirect once, and update everything that points to the old address.

Words in URLs and ranking

A keyword in the URL gives a small relevance hint, and is useful to users and shows bold in results when it matches the query. It is not a strong ranking lever, which is why you should not re-do URLs on an established site merely to add a word. For new pages, though, choose a clean slug at the start.

Common mistakes

  • Dates and IDs in the slug that make it look old or obscure.
  • Duplicate paths with and without a trailing slash, or with http and https.
  • Changing URLs without redirects, creating broken links and lost rankings.
  • Slugs that no longer match the page after a title change (a stable slug is fine; update it only if it is misleading).

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which URL follows best practice?

    Lowercase, hyphen-separated, readable words without file extensions or encoded characters.
  2. 2. What is the fragment of a URL (after the # sign)?

    The fragment identifies a position within the page and is not sent to the server.
  3. 3. What should you do when you must change a page's URL?

    A permanent redirect passes visitors and signals to the new address.
  4. 4. Why can filter and sort parameters hurt SEO?

    Parameter combinations multiply URLs, waste crawl budget and split signals unless managed.

Summary

  • A good URL is readable, lowercase, hyphenated, short and stable; the slug describes the page.
  • Avoid unnecessary parameters, session IDs, file extensions and special characters.
  • Use canonical links for unavoidable duplicates.
  • Change URLs rarely, and always with one-hop permanent redirects and updated links.

Next: Image SEO