Sub topic 2
Handling Special Characters and Non-English Text
Assume you know basic HTML, the a element, its href attribute, and how browsers request pages over HTTP. This chapter focuses on URL decisions that affect crawling, redirects, and internal links.
Handling Special Characters and Non-English Text
A slug is the readable path segment after a domain name. Use lowercase words separated by hyphens. Remove punctuation that adds no meaning. Accented and non-Latin characters need a deliberate policy.
You can keep Unicode characters, but encoded URLs may become difficult to read when copied or logged. Transliteration converts characters to a Latin equivalent, such as crème to creme. It improves consistency for many systems, but can lose meaning or create ambiguous spellings.
import re
import unicodedata
def slugify(title, max_length=60):
text = unicodedata.normalize("NFKD", title)
text = text.encode("ascii", "ignore").decode("ascii").lower()
text = re.sub(r"[^a-z0-9]+", "-", text).strip("-")
return text[:max_length].rstrip("-")
print(slugify("Crème Brûlée Recipe: Easy & Quick!"))
# creme-brulee-recipe-easy-quickChoose one policy for the whole site. Preserve meaningful words, avoid unnecessary encoded characters, and test the result in browsers, servers, analytics, and sharing tools.
Changing a Slug Safely with 301 Redirects
A 301 redirect means a resource has moved permanently. When changing /recipes/creme-brulee to /recipes/creme-brulee-dessert:
- Configure the old URL to return one 301 redirect to the new URL.
- Update internal links, sitemaps, and structured data.
- Keep the redirect while old links may still exist.
- Check that the new URL returns the intended page.
Avoid redirect chains, such as old URL → intermediate URL → final URL. Point the old URL directly to the final destination.
Duplicate URLs and Canonical Tags
The same content can appear at several URLs because of tracking parameters, capitalization, or alternate paths. A canonical tag identifies the preferred URL:
<link rel="canonical" href="https://example.com/recipes/creme-brulee">Use the canonical URL consistently in internal links and sitemaps. Canonical tags are signals, not substitutes for fixing avoidable duplicate URLs.
What Internal Links Do
Internal links connect pages on the same site. They help crawlers discover pages and help distribute context and importance through the site.
Keep important pages reachable through a small number of clicks. Link related pages from hubs, category pages, and relevant articles.
Making Links Crawlable
Use an anchor element with an href. Write anchor text that describes the destination.
<a href="/recipes/creme-brulee">Crème brûlée recipe</a>A JavaScript click handler on a span is not equivalent. Avoid vague text such as “click here.” Use nofollow only for links that should not pass the usual editorial signal, not as a replacement for correct markup.
Exercise
What should you update after changing a page’s slug?
Show answer
Add a direct 301 from the old URL, update internal links and sitemaps, and verify the canonical URL.