DEV Community

Cover image for Do you prefer subdomains or subdirectories?
Madza
Madza Subscriber

Posted on

Do you prefer subdomains or subdirectories?

A subdomain is a URL that allows you to essentially create several websites on a single domain. It’s the blog.yourcompany.com kind of URL.

Subdirectories, on the other hand, are URLs that host subsets of content in separate “folders.” It’s the yourcompany.com/blog kind of URL.

What are your preferred approach to organize website content and rank higher in search results?

Oldest comments (23)

Collapse
 
slimdestro profile image
D\sTro

Creating new directories with same content is like wasting storage and putting extra load on wallet however addons and subdomains are good. Just need to add one more table in the database for url prefix

Collapse
 
andreidascalu profile image
Andrei Dascalu

It's likely that the primal post misuses the term folder as the question clearly refers to the preferred way of serving content, not the actual server storage model.
Aka: whether you put stuff on subdomain or serve via subpaths from the same fqdn.
Whether you actually have folders or it's just internal routing (as you would have in react or symfony) doesn't seem relevant.

Collapse
 
mohammad__amin profile image
MohammadAmin Hakim

I prefer the subdomains. it's easiest to remember for users and you can host your blog or service on another server and point it to this subdomain.

Collapse
 
sqlrob profile image
Robert Myers

The "host on another server" is independent of subdomains versus subdirectories. A reverse proxy will cover that for you.

Collapse
 
yoursunny profile image
Junxiao Shi

Reverse proxy won't work well if two servers are far from each other.

Collapse
 
_garybell profile image
Gary Bell

From a server management perspective, subdomains. It allows much easier separation of code and resources.

From an SEO point, subfolder. Any good points on the main site will help boost the ranking of the blog.

I'm coming at these points from working in a business where the ecommerce is one platform, and the blog is a totally different one on the same tech stack.

Collapse
 
yoursunny profile image
Junxiao Shi

My main website uses subdirectory naming. For example, the blog is at yoursunny.com/t/ .
The reason was that, shared hosting accounts I used initially did not support subdomains.

I tend to use short directory names:

  • /t/: "tech blog", now it's more than tech contents
  • /p/: projects
  • /m/: "me", now it's contact information and social media posts

The structure was designed in 2006, although there has been changes during the 2017 rebuild. Most of the links in past 15 years are still working, thanks to redirects.

Scripts on this website are written in PHP so they can go into subdirectories easily.


When it comes to pages published from GitHub Actions, Node.js or Go servers, etc, it would be difficult to use subdirectories. My new domain ndn.today arranges contents in subdomains. I'm getting many emails about TLS certificate issuance.

Collapse
 
rzeczuchy profile image
rzeczuchy

From a user standpoint, I expect a subdirectory (example.com/blog) to follow the same UI as the main site (example.com). A subdomain in my mind will be a separate entity with its own UI.

Collapse
 
vampiire profile image
Vamp

that’s such a concise way of describing their distinction. thanks for sharing

Collapse
 
jacobreidwd profile image
Jacob Reid

I couldn't agree more. I feel subdomains can be useful if you are going for a subproject per se, but if you are working on the same project, website, ect. I'd definitely recommend the use of subdirectories.

Collapse
 
shelbyspees profile image
shelby spees (she/her) • Edited

This is exactly how I have things set up:

  • Hugo personal site shelbyspees.com
  • GitBook notes site notes.shelbyspees.com
  • Notist speaker portfolio speaking.shelbyspees.com

I deploy my Hugo site with Netlify, and I can also manage my subdomains there for these third-party services. Within my personal site I have subdirectory paths like /posts and /about, all built with Hugo and using the same styling.

Collapse
 
raguay profile image
Richard Guay

If it’s the same subject/idea/project/technology stack, only use subdirectories.

If it’s some new idea/project but the same technology stack, subdomains are best.

If it’s a new technology stack totally different than the original, then move to a new domain.

Collapse
 
cicirello profile image
Vincent A. Cicirello

I use a combination of the two. My main website has several subdirectories for things like my publications, research, teaching, etc, some of those with their own subdirectories. But then I use subdomains for websites for software projects such as hosting API documentation, such as chips-n-salsa.cicirello.org/ and jpt.cicirello.org/ . For the part of your question concerning ranking, I'm not sure. I didn't organize it that way for SEO purposes. I did it more for convenience. I suspect that it might not matter as much to SEO as some believe. I base this on Google's search console, which seems to treat everything within the domain as a single entity.

Collapse
 
victoredier profile image
Victor Edier

Subdomains when possible, it allows separate resources from your main site/app

Collapse
 
cchana profile image
Charanjit Chana

For me subdomains lead to a better organisation of code (has also caused duplication in some cases).

I use "subfolders" for SEO purposes, giving some structure to the project that is predictable.

Collapse
 
exceedteam profile image
Igor T • Edited

Now I use subfolders, before it was subdomains, and I can say that after moving to subfolders my real estate pages starts be better indexing. The effect was not only for that page but for others as well. Hope that helps