URL Structure

Design clean, descriptive URLs that help users and search engines.

A good URL is short, readable, and describes the page. It appears in the SERP and is easy to share.

Best practices

  • Use lowercase words separated by hyphens, not underscores.
  • Include the primary keyword.
  • Keep it short - drop filler words like and, the.
  • Avoid dates and long ID strings when possible.
  • Use a logical folder structure that mirrors your site.

Example

Example Β· bash
# Good
https://example.com/coffee/pour-over-guide

# Bad
https://example.com/index.php?id=8842&cat=3&ref=xy
https://example.com/Coffee/Pour_Over_Guide_FINAL_v2

When to use it

  • A developer migrates an e-commerce site from auto-generated ID-based URLs (/product?id=4821) to keyword-rich slugs (/shoes/trail-runner-pro/) to improve ranking signals.
  • An international site uses language-prefixed URLs (/fr/chaussures-trail/) so Google can correctly identify and serve the right language version to each audience.
  • A blog enforces lowercase, hyphenated URLs via a server-side redirect rule to prevent duplicate content from URL casing variations.

More examples

Clean URL vs messy URL comparison

Clean, keyword-rich URLs are easier for users to read, copy, and link to, and provide an additional relevance signal for the target keyword.

Example Β· bash
# Poor: dynamic parameters, no keywords, uppercase
https://example.com/index.php?cat=12&pid=4821&ref=HP

# Better: keyword-rich, lowercase, hyphen-separated, short path
https://example.com/shoes/trail-runner-pro/

# International: language in path prefix
https://example.com/fr/chaussures/trail-runner-pro/

Nginx redirect: enforce lowercase URLs

Enforcing lowercase and consistent trailing-slash rules at the server level prevents duplicate content from URL casing and slash variations.

Example Β· bash
# nginx.conf β€” redirect uppercase URLs to lowercase canonical form
server {
    # Rewrite any URL with uppercase letters to its lowercase equivalent
    if ($uri != $uri_lower) {
        return 301 $scheme://$host$uri_lower$is_args$args;
    }
    # Catch trailing slash inconsistency
    rewrite ^([^.]*[^/])$ $1/ permanent;
}

Slug generator in Python

A slug generator function normalises titles to lowercase, ASCII, hyphenated slugs β€” removing characters that would create crawl or duplicate-content issues.

Example Β· bash
python3 - << 'EOF'
import re, unicodedata

def make_slug(title: str) -> str:
    """Convert a page title to an SEO-friendly URL slug."""
    slug = unicodedata.normalize('NFKD', title.lower())
    slug = slug.encode('ascii', 'ignore').decode('ascii')
    slug = re.sub(r'[^a-z0-9\s-]', '', slug)
    slug = re.sub(r'[\s-]+', '-', slug).strip('-')
    return slug

titles = ["Trail Runner Pro 2024", "Best CRM Software & Tools", "FAQ: How to rank #1?"]
for t in titles:
    print(f"{t!r:40} -> /{make_slug(t)}/")
EOF

Discussion

  • Be the first to comment on this lesson.
URL Structure β€” SEO with AI | SoundsCode