
Subdomain vs. Subdirectory: Which Is Better for SEO?
Few SEO debates have lasted as long as this one: should your blog, store, help center, or regional site live at blog.example.com or at example.com/blog? Marketers swear subdirectories always win, some developers prefer the clean separation of subdomains, and Google says it does not really matter. The truth sits somewhere in between, and it depends far more on how your site is built and managed than on the URL pattern itself. This article explains how search engines treat each structure, the practical trade-offs, when each one makes sense, and how to implement both, including a reverse proxy that lets you serve a separately hosted app from a subdirectory. If you need the DNS basics first, see how to set up subdomains in DNS settings.
Subdomains and Subdirectories Defined
A subdomain is a label added to the left of your registered domain. In blog.example.com, blog is the subdomain of example.com. Technically, www is also a subdomain. Each subdomain can have its own DNS records, so it can point to a completely different server, platform, or provider.
A subdirectory (also called a subfolder) is a path after the domain. In example.com/blog, /blog is a directory on the same host. All subdirectories share the same hostname, the same DNS records, and normally the same server or platform.
| Aspect | Subdomain (blog.example.com) | Subdirectory (example.com/blog) |
|---|---|---|
| DNS | Its own record (A, AAAA, CNAME) | Shares the main domain's records |
| Hosting | Can be on any server or SaaS platform | Same host, or routed by a reverse proxy |
| TLS certificate | Needs coverage (SAN or wildcard) | Covered by the main certificate |
| Cookies | Separate unless scoped to parent | Shared with the rest of the site |
| Search Console | Separate property, or a Domain property | Included in the main URL-prefix property |
| Analytics | May need cross-domain configuration | Works out of the box |
| Perceived by users as | A related but distinct section | Part of the main site |
What Google Actually Says
Google's public position, repeated by its search advocates over many years, is that its systems can handle both structures and that you should choose whichever is easiest for you to maintain. Google says it crawls and indexes subdomains and subdirectories alike, and that it works out over time which parts of a domain belong together.
There are important nuances:
- Google has said it may treat a subdomain as part of the main site or as a separate site depending on how related the content is and how it is linked. A user-generated content platform where every user gets a subdomain is clearly a set of separate sites. A company blog at
blog.example.comthat is heavily linked fromexample.comis usually understood as part of the same property. - Search Console treats them differently for reporting. A URL-prefix property for
https://www.example.com/does not includeblog.example.com, while a Domain property (verified via DNS) covers every subdomain and protocol. - Google evaluates many signals at the page level. A great article ranks because it is a great article, regardless of whether a dot or a slash comes before
blog.
Other search engines publish less guidance, but the same general principle applies: clear internal linking and a coherent site structure matter more than the URL shape.
Why Many SEOs Still Prefer Subdirectories
Despite Google's neutral stance, a lot of practitioners report that moving content from a subdomain into a subdirectory improved rankings. There are some practical reasons this happens, even if the URL pattern itself is not a ranking factor:
- Internal linking gets better. When the blog lives in the same CMS or template as the main site, it naturally shares navigation, footers, related-content modules, and breadcrumbs. More internal links flow in both directions.
- Links are consolidated. Backlinks pointing to
example.com/blog/...andexample.com/productare all on one host, which makes it easier for search engines to see one strong site instead of two weaker ones. - Technical consistency. A single host means one
robots.txt, one sitemap index, one set of canonical rules, and one migration to manage. - Migrations often fix other problems. Moving a neglected subdomain blog usually comes with redesigns, content pruning, and better templates, so the improvement cannot be attributed purely to the URL change.
Treat case studies on either side with caution. They are rarely controlled experiments.
When a Subdomain Makes More Sense
Subdomains are the right tool in plenty of situations:
- Different platforms. Your main site is a Next.js app, your help center is a hosted SaaS knowledge base, and your status page is a third-party service. Each can be pointed at with a single
CNAMErecord. - Genuinely separate audiences or products, such as a developer portal, an app dashboard (
app.example.com), or a community forum. - Content you do not want indexed alongside the main site, such as a staging environment or a logged-in application. (Protect staging with authentication, not just
robots.txt.) - Security isolation. Cookies and browser origins are separated by default. User-uploaded content is often served from a separate host to reduce the risk of cross-site scripting affecting the main site.
- Organisational boundaries. Different teams can own and deploy their subdomains independently.
When a Subdirectory Makes More Sense
- Content marketing that supports the main site, such as a blog, guides, or resources, where you want the content to strengthen the main domain.
- Product or category pages that are part of the same purchase journey.
- Language or regional versions of a single brand site, such as
example.com/de/andexample.com/fr/, managed withhreflang. Google documents subdirectories, subdomains, and country-code domains as valid options; subdirectories are usually the easiest to run. - Small teams that want one CMS, one analytics setup, and one place to fix technical SEO issues.
Decision Checklist
Ask these questions in order:
- Is the content on a different platform that cannot be served from your main host? If yes, either use a subdomain or put a reverse proxy in front of it (see below).
- Is the content for the same audience and part of the same journey? If yes, prefer a subdirectory.
- Does it need separate security boundaries or separate cookies? If yes, use a subdomain.
- Will one team maintain everything? If yes, a subdirectory is simpler.
- Is there an existing structure with rankings? If it works, a migration has costs and risks. Change it only for clear reasons.
How to Set Up a Subdomain
A subdomain only needs a DNS record. To point blog.example.com at a hosted platform, add a CNAME:
; BIND zone file snippet for example.com
blog 3600 IN CNAME example-blog.hosting-provider.net.
docs 3600 IN CNAME custom.docs-platform.io.
app 3600 IN A 203.0.113.20
Then verify the record resolves:
dig +short blog.example.com CNAME
dig +short blog.example.com
Remember to cover the subdomain with a TLS certificate. Most hosted platforms issue one automatically once the CNAME resolves. If you remove the service later, delete the record too, or you risk a dangling DNS record that attackers can take over.
How to Serve a Separate App From a Subdirectory
What if your blog runs on WordPress on one server, but you want it at example.com/blog instead of a subdomain? A reverse proxy on the main host can forward requests for /blog/ to the other server while the browser only ever sees example.com.
Nginx Reverse Proxy
server {
listen 443 ssl;
http2 on;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# Main application
location / {
proxy_pass http://127.0.0.1:3000;
}
# Blog hosted elsewhere, served under /blog/
location /blog/ {
proxy_pass https://blog-origin.example.net/blog/;
proxy_set_header Host blog-origin.example.net;
proxy_set_header X-Forwarded-Host example.com;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ssl_server_name on;
}
}
The backend application must be configured to generate URLs, canonical tags, and sitemaps using https://example.com/blog/, not its own origin hostname. For WordPress, that means setting the site address to https://example.com/blog. Otherwise you will leak the origin hostname into links and canonicals and create duplicate content.
Next.js Rewrites
If your main site is built with Next.js, rewrites in next.config.mjs achieve the same thing without touching Nginx:
/** @type {import('next').NextConfig} */
const nextConfig = {
async rewrites() {
return [
{
source: "/blog/:path*",
destination: "https://blog-origin.example.net/blog/:path*",
},
];
},
};
export default nextConfig;
Edge platforms such as Cloudflare Workers and Vercel offer equivalent routing features.
Migrating From a Subdomain to a Subdirectory
If you decide to move blog.example.com to example.com/blog, treat it like any other site migration:
- Map every old URL to its new URL, one to one.
- Publish the content at the new location with correct canonical tags pointing to themselves.
- Add permanent 301 redirects from each old URL to its new equivalent.
- Update internal links, sitemaps, and structured data to the new URLs.
- Monitor crawling and indexing in Search Console, using a Domain property so both hosts are visible.
A single Nginx server block on the old subdomain handles the redirects when the paths simply move under /blog:
server {
listen 443 ssl;
http2 on;
server_name blog.example.com;
ssl_certificate /etc/letsencrypt/live/blog.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.example.com/privkey.pem;
return 301 https://example.com/blog$request_uri;
}
Test a sample of old URLs with curl -sI and confirm each returns a single 301 to the right destination. For redirect patterns in general, see what domain forwarding is and how to set it up, and for WordPress specifically, how to set up 301 redirects in WordPress.
Subdomain vs. Subdirectory FAQ
Sometimes. Google says it can treat subdomains either as part of the main site or as separate sites depending on the content and how it is connected. A company blog that is well linked from the main site is usually understood as related; independent user sites on subdomains are treated as separate.
No. Google states that both structures work. Subdirectories are often easier to manage and naturally share internal links and authority, which is why many SEOs prefer them, but a well-run subdomain can rank perfectly well.
Yes. Technically www is a subdomain of your registered domain. It is just a conventional one that most sites use, or redirect away from, as their primary hostname.
Either works, as do country-code domains. Subdirectories such as example.com/de/ are usually the simplest to manage and share the main domain's strength. Whichever you choose, use hreflang annotations to connect the language versions.
They may help indirectly, especially when the subdomain links heavily to the main site, but links to pages on the same host consolidate more directly. This is one of the main practical arguments for subdirectories.
Yes. A reverse proxy such as Nginx, a CDN worker, or framework rewrites can route a path like /blog/ to a separate server while visitors only see your main domain.
There is usually a temporary fluctuation during any migration. With one-to-one 301 redirects, updated internal links, and correct canonicals, most sites recover and often benefit from better integration with the main site.
Conclusion
Search engines can rank content on subdomains and subdirectories alike, so the URL pattern alone is not a ranking factor. What changes the outcome is everything that tends to come with each choice: how well the content is linked into the rest of the site, whether links and signals are consolidated, and how easy it is for your team to keep the technical SEO in order. For content that supports your main site, a subdirectory usually wins on those practical grounds.
Use subdomains when the content genuinely is a separate product, platform, audience, or security boundary. If a platform forces a subdomain but you want a subdirectory, a reverse proxy gives you the best of both. And if you already have a structure that ranks, weigh the cost of a migration carefully before changing it.
Here are some useful references for going deeper on site structure and SEO:
- Google Search Central: Site Moves With URL Changes — Google's guide to moving content between hosts and paths.
- Google Search Central: Managing Multi-Regional and Multilingual Sites — compares ccTLDs, subdomains, and subdirectories for international sites.
- Google Search Console Help: Add a Website Property — explains Domain properties versus URL-prefix properties.
- Nginx: ngx_http_proxy_module — official documentation for
proxy_passand related directives. - Next.js Docs: rewrites — how to map a path to an external destination.


