Subdomains vs. Subdirectories
Compare subdomains and subdirectories for blogs, shops and apps, covering setup, security boundaries, search and upkeep.
Key takeaways
- A subdomain is a separate hostname with its own DNS records, while a subdirectory is a path handled by whatever serves the main hostname.
- Browsers treat each subdomain as a different origin, which helps isolation and adds work for sharing data.
- Search engines can index both, so the better predictor of results is quality, internal linking and consistent maintenance.
- Choose based on infrastructure and ownership first, and avoid moving later without a redirect plan.
A subdomain puts a section of your site at its own hostname, such as blog.example.com. A subdirectory puts it at a path under the main hostname, such as example.com/blog/. If the section is part of the same site, run by the same team and meant to feel like one thing, a subdirectory is usually the simpler choice. If it's a separate application, runs on different infrastructure or needs isolation, a subdomain often fits better.
Neither is wrong. The differences show up in DNS, certificates, cookies, security boundaries, search and the amount of plumbing you maintain.
The mechanics
In a URL, the hostname comes before the first single slash and the path comes after. See URL anatomy for all the parts.
A subdomain exists because you add DNS records for it. It can point anywhere: a different server, a hosting platform or a CDN. You don't register or pay for subdomains separately. You create as many as your DNS provider allows.
shop.example.com. 3600 IN CNAME stores.example.net.
docs.example.com. 3600 IN A 192.0.2.40 A subdirectory needs no DNS change at all. Requests go to the same place as the rest of the site, and the web server or application decides what to return for each path. The folder doesn't even have to exist on disk.
Comparing them
| Question | Subdomain | Subdirectory |
|---|---|---|
| DNS setup | New record needed | None |
| Certificate | Must cover the new name | Already covered |
| Different platform | Easy: point the record there | Needs a reverse proxy or CDN routing |
| Cookies and storage | Separated by default | Shared across the site |
| Analytics and sitemaps | May need extra configuration | One property, usually simpler |
| Failure isolation | Can run independently | Often shares fate with the main site |
Security and isolation
Browsers define an origin as the combination of scheme, hostname and port. blog.example.com and www.example.com are therefore different origins. Scripts on one can't freely read pages or local storage belonging to the other, and requests between them are subject to CORS rules. Paths on the same hostname share an origin, so a vulnerability in a forum at /forum/ can affect the account area at /account/.
Isolation between subdomains is partial. They're usually considered the same "site", and cookies set with a Domain attribute of example.com are sent to all of them. A careless or compromised subdomain can set cookies that the others receive. For sensitive session cookies, leave the Domain attribute off so the cookie stays with one host, and consider the __Host- prefix, which requires that. How cookies work explains the attributes.
For truly untrusted content, such as files uploaded by users, a completely separate registered domain gives a stronger boundary than a subdomain.
Subdomains also accumulate. A record that still points at a hosting service you cancelled may be claimable by someone else. Remove unused records, as described in dangling DNS.
Certificates
A certificate must list each hostname it protects, or use a wildcard. *.example.com covers blog.example.com and shop.example.com, but not example.com itself or a.blog.example.com. Automated issuance makes per-host certificates easy on most platforms. If you restrict issuers with CAA records, remember that a hosted subdomain may need a different authority.
Search considerations
This is where opinions run strong. Major search engines have said they can crawl and rank either structure. Many site owners report that content in a subdirectory benefits more readily from the main site's reputation and links, while others see no meaningful difference. Controlled evidence is hard to produce, because moving content changes many things at once.
Practical points are clearer:
- Link generously between the section and the main site, whichever you choose. See internal linking.
- Give each hostname its own
robots.txtfile. A subdomain doesn't inherit the main one. - Include the pages in sitemaps and add the hostname to your search console tools if needed.
- Avoid serving the same content on both. Pick one address and redirect the other.
Putting a separate platform in a subdirectory
You may want example.com/blog/ while the blog runs on different software. A reverse proxy or CDN rule can forward that path to another server.
It works well, but watch for absolute links that drop the prefix, cookie paths, redirects that expose the internal hostname, caching rules and one more component that can fail. Some hosted platforms don't support this arrangement at all. If yours doesn't, a subdomain may be the realistic option.
Operations and upkeep
Every hostname is something to look after. Each needs working DNS, a valid certificate, security headers, monitoring and someone who knows why it exists. Ten subdomains on ten platforms means ten places for a certificate to fail or software to go unpatched. A single hostname concentrates the work, which is simpler until one component takes the others down with it.
Ownership often settles the question. If a separate team or vendor runs a section and needs to deploy on its own schedule, a subdomain gives them a clear boundary: they control their server, and you control one DNS record. If the same people publish everything with the same tool, separate hostnames add settings without adding value.
Think about measurement too. Analytics tools may treat a visit that crosses from www to shop as one journey or two, depending on how cookies and settings are configured. Check that sign-ups or purchases that span both are counted once.
Common mistakes
- Forgetting the certificate. A new DNS record goes live and visitors see a warning because nothing issued a certificate for the name.
- Assuming a wildcard DNS record is harmless. A
*record makes every mistyped label resolve, which can hide errors and widen what a misconfigured service exposes. - Leaving test sites public. Names like
devandoldoften run outdated software with real data. Require a login or take them down. - Splitting one topic across both. Half the help articles at
help.example.comand half under/help/confuses readers and editors alike. Choose one home. - Letting email settings lapse. A subdomain that sends mail needs its own authentication records, and one that never sends should be covered by your domain's policy. See DMARC explained.
Typical choices
- Blog or help articles for the same business: subdirectory, if your platform allows it.
- Web application with logins: subdomain such as
app.example.com, separate from the marketing site. - Hosted store or support desk: subdomain, because the vendor expects a DNS record.
- Languages or regions: often subdirectories like
/fr/for easy upkeep. Subdomains or country domains when teams or hosting differ. - Staging and testing: subdomain with access control, kept out of search. See staging sites.
- APIs: either works. A subdomain makes it easy to route and scale independently.
A worked example
Say you run a small furniture workshop at example.com. You want to add three things: articles about wood care, an online store from a hosted vendor and a private order-tracking tool a developer is building.
The articles are ordinary content that your existing site software can publish, so they go under example.com/care/. They share navigation, certificate and analytics, and there is nothing new to maintain.
The hosted store asks you to create a CNAME record, so it becomes shop.example.com. You check that the vendor can issue a certificate for that name, that your CAA records allow its authority, and that links lead back and forth between the shop and the main site.
The tracking tool holds customer details and is deployed by someone else. It gets orders.example.com, with session cookies limited to that host. A test copy lives behind a password and is removed when the project ends.
If the developer relationship later ends, you delete one record and the tool is gone, without touching the rest. If the store vendor changes, you repoint one record and redirect the old product addresses. The structure follows who operates each piece, which tends to age better than a rule picked for its own sake.
Changing your mind later
Moving from one structure to the other changes every URL in the section. Plan it like any migration:
- Make a list of old addresses.
- Map each to a new one.
- Set up permanent redirects, one to one, keeping the old hostname alive to serve them.
- Update internal links, canonical tags and sitemaps.
- Watch error logs and search traffic for several weeks.
How to redirect pages covers the details. Expect some fluctuation, and don't move purely on a hunch about rankings.
Common questions
Is www a subdomain?
Yes. It's an ordinary label under your domain, kept by convention. Pick either the bare domain or www as the main address and redirect the other.
Can a subdomain use a different DNS provider?
Yes. You can delegate a subdomain with NS records so another set of name servers answers for everything beneath it. That suits separate teams or platforms, and it adds one more thing to keep working.