Sub topic 2
The parts of a URL
This chapter assumes you know basic HTML (the a element and its href attribute) and roughly how a browser requests a page over HTTP. It does not assume SEO experience. By the end you should be able to split any URL into its parts and say which parts a search engine treats as distinct. You should also be able to say which part you control when you choose a slug.
Why a URL is more than an address
A URL (Uniform Resource Locator) is the string that identifies one resource on the web. Search engines use it as the identity of a page. They store each page under its URL, and they decide whether two pages are the same by comparing URLs. A URL is also the first piece of text a reader or crawler sees before loading anything.
A crawler treats two URLs that differ by a single character as two different pages until it has evidence otherwise. Many duplicate-content problems come from this rule. Learning the parts of a URL tells you where those differences can appear.
The anatomy of a URL
Take this address:
https://www.example.com:443/blog/url-slugs/?utm_source=news&page=2#examplesIt breaks down as follows.
| Part | Example value | Role |
|---|---|---|
| Scheme | `https` | The protocol used to fetch the page |
| Host | `www.example.com` | The server name, made of subdomain, registered domain, and top-level domain |
| Port | `443` | The network port, usually omitted because each scheme has a default |
| Path | `/blog/url-slugs/` | Which resource on the host, written as segments separated by `/` |
| Query string | `utm_source=news&page=2` | Name and value pairs after `?` |
| Fragment | `examples` | A position inside the page, after `#` |
The scheme is followed by ://. Between the scheme and the path sits the authority. It consists of the host and an optional port, and it can also carry user credentials, which you will almost never see on public sites.
Scheme
The scheme for public sites is http or https. For search engines, http://example.com/ and https://example.com/ are different URLs. HTTPS is the standard, so a site should serve one scheme and redirect the other to it. The redirect mechanics are covered in a later chapter.
Host
The host is read from right to left:
- The top-level domain (TLD) is the last label, such as
comororg. - The registered domain is the name you buy plus the TLD, such as
example.com. - A subdomain is any label added to the left, such as
wwworblog.
www.example.com and example.com are different hosts, so they are different URLs. Search engines also commonly treat blog.example.com as a separate site from example.com, at least for reporting and for how authority is assessed. This gives you a real design choice.
| Choice | Example | Consequence |
|---|---|---|
| Subdirectory | `example.com/blog/` | Content sits in one site. Internal links and reporting stay together. |
| Subdomain | `blog.example.com` | Content can be hosted separately, but it is often analyzed as its own site. |
For most content, such as a blog or documentation, a subdirectory is the simpler default. Use a subdomain when a separate system or team really needs one.
Hosts are case-insensitive. Example.COM and example.com reach the same server, and clients normalize the host to lowercase.
Port
The port is almost always invisible. HTTP defaults to 80 and HTTPS to 443, so https://example.com:443/ and https://example.com/ mean the same thing. A non-default port, such as :8080, makes a different URL. Seeing one in a public link usually means a staging server or a misconfiguration has leaked.
Path
The path identifies the resource on the host. It looks like a folder hierarchy, and many sites mirror their structure in it:
/blog/url-slugs/
│ └── last segment: the slug
└── parent segment: a sectionThe last segment of the path is usually the slug. It is the human-readable label for one page, and it is the part of the URL you write yourself. The next two chapters cover what a slug is and how to write good ones. For now, notice that everything before the slug (the host and parent segments) is set by your site structure. The slug is the part an author edits.
Unlike the host, the path is case-sensitive on most servers. /Shoes and /shoes can be two different pages, or one page and one error. Search engines also treat them as different URLs. Trailing slashes matter in the same way. /shoes and /shoes/ are different URLs, and a server may serve identical content at both.
Query string
The query string starts after the first ?. It holds name=value pairs separated by &. Applications use it to pass inputs to the page:
?page=2selects a page of results.?sort=pricechanges the order of a listing.?utm_source=newsrecords where a visitor came from.
Each combination of parameters is a new URL. A category with three sort options, four filters, and a page number can generate hundreds of addresses that show nearly the same products. A crawler may spend its visits on these variants instead of on your important pages. Parameters that change what the page shows can be legitimate. Parameters that only track a visit add no value to search.
Parameter order also produces distinct strings. ?a=1&b=2 and ?b=2&a=1 look different even though most applications treat them the same.
Fragment
The fragment starts at #. Browsers use it to scroll to an element with a matching id, and the browser does not send it to the server. As a result, /guide/#examples and /guide/ request the same resource. Search engines generally ignore fragments when identifying a page. Fragments are fine for jump links within a long page, but you cannot use them to give separate content a separate indexable address.
Reading a URL with code
Python's standard library can split a URL for you. This is useful for audits and for sanity-checking what you will later compare.
from urllib.parse import parse_qs, urlsplit
url = "https://www.example.com:443/blog/url-slugs/?utm_source=news&page=2#examples"
parts = urlsplit(url)
print(parts.scheme) # https
print(parts.hostname) # www.example.com
print(parts.port) # 443
print(parts.path) # /blog/url-slugs/
print(parts.query) # utm_source=news&page=2
print(parts.fragment) # examples
print(parse_qs(parts.query)) # {'utm_source': ['news'], 'page': ['2']}
# The slug is the last non-empty path segment
segments = [s for s in parts.path.split("/") if s]
print(segments[-1]) # url-slugsurlsplit lowercases the scheme, and its hostname attribute is lowercased as well. It leaves the path alone, which matches how most servers behave.
What counts as a different page
A function can approximate how a crawler compares URLs. This one lowercases what is safe to lowercase, drops a default port, ignores the fragment, and treats an empty path as /. It keeps the path's case, the trailing slash, and the query exactly as written.
from urllib.parse import urlsplit
DEFAULT_PORTS = {"http": 80, "https": 443}
def comparison_key(url):
parts = urlsplit(url)
host = parts.hostname or ""
if parts.port not in (None, DEFAULT_PORTS.get(parts.scheme)):
host = f"{host}:{parts.port}"
return (parts.scheme, host, parts.path or "/", parts.query)
variants = [
"HTTPS://Example.com:443/Shoes",
"https://example.com/shoes",
"https://example.com/shoes/",
"https://example.com/shoes?color=red&size=9",
"https://example.com/shoes?size=9&color=red",
"https://example.com#top",
"https://example.com/",
]
for url in variants:
print(comparison_key(url))
print(len({comparison_key(u) for u in variants})) # 6Seven strings produce six distinct keys. Only the last two collapse into one, because the fragment is dropped and an empty path becomes /. The first two differ by the case of the path. The third adds a trailing slash. The fourth and fifth differ only in parameter order, and the function does not sort the query, so it keeps them apart, as a simple crawler would.
How the parts map to SEO decisions
Two parts need most of your attention.
- The path, especially its slug, is the part you write by hand and the part readers see in results and shared links.
- The scheme, host, trailing slash, and query string are where accidental duplicates come from. They are decided by configuration, not by writing, so they are easy to leave inconsistent.
Common errors
- Mixed host forms. The site answers at both
example.comandwww.example.comwithout a redirect, so every page exists twice. - Mixed schemes. Pages are reachable over HTTP and HTTPS, and internal links use both.
- Inconsistent trailing slashes. Some internal links point to
/guide, others to/guide/. The server answers both with 200 instead of redirecting one to the other. - Uppercase in paths. An editor types
/Blog/URL-Slugs/. A mixed-case path works until someone links to the lowercase version, and then you have two addresses. - Index file names exposed.
/products/and/products/index.htmlreturn the same page. - Session IDs or tracking in internal links. A link in your own navigation that carries
?utm_source=or?sessionid=hands crawlers a new URL for every page. - Using fragments as pages. A single-page app that routes with
#/products/shoesgives crawlers one URL for everything.
The remedies come in later chapters. Redirects and slug changes come first, then canonical tags, which name a preferred URL when duplicates exist. Prevention is cheaper than cleanup, so settle your conventions early:
- Use HTTPS only.
- Choose
wwwor non-www. - Choose a trailing-slash rule.
- Keep paths lowercase.
- Link internally to the exact form you chose.
Where this leads
Every chapter that follows works with one or more of these parts. Slug chapters concentrate on the last path segment. The chapter on duplicate URLs deals with variants of scheme, host, slash, and query. Internal link chapters rely on the fact that the href you write must match the URL you intend to rank.
Exercise
Which of these URLs does a crawler treat as the same page as https://example.com/guide/, and why? (a) https://example.com/guide/#faq, (b) https://example.com/guide, (c) https://example.com/Guide/, (d) https://example.com:443/guide/, (e) http://example.com/guide/
Show answer
Only (a) and (d). In (a) the fragment is not sent to the server and is ignored for identifying the page. In (d) port 443 is the default for HTTPS, so it is the same address. Options (b) and (c) differ by the trailing slash and by path case, and (e) differs by scheme, so each is a separate URL unless the server redirects it.
Exercise
A shop's category page https://shop.example.com/shoes/ is reachable with ?sort=price, ?sort=name, and ?sort=price&page=2. Name two URL parts involved, say why this is a problem for crawling, and say which part you would choose to host the shop if you wanted it analyzed together with the main site.
Show answer
The query string creates the extra variants, and the host (a subdomain) is the other part. Each parameter combination is a separate URL, so crawlers can spend visits on near-duplicates instead of important pages. Using a subdirectory, such as example.com/shop/shoes/, keeps the shop inside the main site instead of a separate subdomain that is often analyzed on its own.
Exercise
In https://example.com/blog/2026/url-slugs/, which part is the slug, and which parts of the URL are set by site structure rather than by the author of this page?
Show answer
The slug is url-slugs, the last path segment. The scheme, host, and the parent segments /blog/ and /2026/ come from site configuration and structure.