3v-Hosting Blog

What Are Subdomains and How to Use Them

DOMAINS

8 min read


A subdomain is a domain located below another domain in the DNS hierarchy. For example, blog.example.com is a subdomain of the top-level domain example.com. Such names are often used for blogs, personal accounts, APIs, and other services that need their own address within a shared corporate domain.

However, it goes without saying that creating a subdomain must also be accompanied by configuring the DNS, web server, and HTTPS so that the application you need opens on that subdomain.

 

 

 

How a subdomain name is structured

It is customary to read the domain name hierarchy from right to left. For example, in the address shop.example.com, the "com" part denotes the top-level domain, "example.com" is the second-level domain, and "shop.example.com" is the third-level domain.

A subdomain does not necessarily have to be at the third level - there are also subdomains at higher levels. For example, dev.shop.example.com is a fourth-level subdomain of shop.example.com.

The familiar "www" that precedes the main domain is, in fact, also a subdomain. Yes, the names example.com and can both lead to the same website, but this requires the appropriate settings.

The owner of the main domain example.com usually creates subdomains on their own, without having to purchase each name from their registrar. However, a DNS provider or hosting plan may limit the number of records and websites that can be hosted.

 

 

 

 

What Subdomains Are Used For

Assigning a separate address is particularly convenient when a service has its own specific purpose and develops independently of the main website. For example, example.com hosts the company’s public website, account.example.com hosts the users’ personal account portal, and api.example.com hosts the API for a mobile app.

Moreover, a low-traffic corporate website can remain on standard hosting, while the resource-intensive user portal can be moved to a more powerful VPS server. Yes, subdomains can be directed to any other servers, regardless of which server the main domain is hosted on.

Development teams very often use subdomains to divide the development environment into isolated environments. For example, the subdomain dev.example.com is used for development itself; the subdomain staging.example.com is often set aside for testing and rolling back changes; and the subdomain prod.example.com can be reserved for a fully ready and tested application. Here, it all depends on a company’s specific practices.

 

 

 

 

How a Subdomain Differs from a Subfolder

It’s very simple. In the address blog.example.com, the hostname changes, whereas in example.com/blog/, the path within the main website itself changes. This is the main technical difference. DNS works directly with hostnames and does not determine which application should serve the path to the /blog/ directory within the website.

At the same time, it’s important to understand that a subfolder in the URL doesn’t necessarily correspond to an actual folder on the disk, since requests to /blog/ can be handled, for example, by a CMS or a separate application behind a reverse proxy. It’s also possible to set up various redirects, but that’s beyond the scope of this article.

If the blog uses the same CMS, the same templates, and the same login system as the main website, then the /blog/ path is often easier to maintain. However, for a separate documentation platform or client dashboard, a subdomain may be much more convenient, since it is easier to route it to a different server or connect it to an external service.

However, a separate domain name does not provide isolation of files, processes, and databases. Two websites running under the same system user with access to shared files remain interconnected regardless of their addresses. Isolation is configured using operating system tools, containers, or virtual machines.

 

 

 

 

How to Create a Subdomain

Now let’s move on to the practical steps. To create a new subdomain for an existing website, you’ll need access to the main domain’s DNS management and the ability to add a new name on the hosting or application side. Before making any changes, check whether the selected subdomain is already in use by another service, and save the current record values if you plan to change them.

 

Add a DNS Record

Records are edited with the provider whose authoritative DNS servers host your main domain. This could be a domain registrar, a hosting provider, or a separate DNS platform. Keep in mind that if DNS is managed outside of your hosting provider, simply creating a site in the hosting control panel will not update the external DNS zone.

To connect directly to the server, an A record with an IPv4 address is typically used. In the example.com zone, you need to specify the A record type, the name "blog", and the server’s actual public IPv4 address. Many control panels automatically add the parent domain, so before saving, verify that the result is specifically blog.example.com.

For IPv6, use an AAAA record. However, you should only add it if the server actually accepts connections at that address and the website is configured for IPv6. An incorrect AAAA record can cause problems for some visitors even if the A record is correct.

That said, it’s usually not necessary to create a separate DNS zone for each subdomain, since delegation via NS records is only required when control of a child zone is transferred to other DNS servers.

 

Set up the website on the server

After configuring the DNS, you need to add the full name blog.example.com in the settings of your hosting provider, web server, or external platform. There, you also specify which files or application serve this address.

A single IP address can serve multiple websites. In Nginx, the name is specified using the `server_name` directive in the corresponding `server` block. If there is no matching name in the configuration, the request may be directed to the default website. You can read more about installing and initially configuring the Nginx web server in this article.

On a live server, before changing the configuration, save a copy of it, then check the syntax using the web server’s built-in tools, and only apply the changes after a successful check. The specific files and method of application depend on your installation. For example, some control panels may automatically generate the configuration and overwrite manual edits.

 

Enable HTTPS

The certificate system works such that a specific certificate must cover the name that a visitor enters in the browser. Thus, a certificate issued only for example.com does not automatically apply to blog.example.com.

 

To solve this problem, you can either issue a separate certificate for the subdomain or include multiple names in a single certificate.

It’s also possible to obtain a wildcard certificate with the name *.example.com, which will cover all subdomains of a single main domain, such as blog.example.com and shop.example.com. However, such a certificate does not cover example.com itself or lower-level nested subdomains like dev.blog.example.com. For those, you’ll need additional names in the certificate or separate certificates.

 

 

 

 

 

How to Check a Subdomain Configuration

All DNS responses are cached at various levels, from the browser to the root DNS servers; therefore, after changing a record for your domain, different users may receive different values for a while. The specific duration of this inconsistency can depend on many factors, including the TTL of the previous record. A response indicating that a particular domain name does not exist may also be cached - this is known as a negative cache.

If you have the BIND `dig` utility installed on your computer, you can check the current records using the following commands:

dig blog.example.com A
dig blog.example.com AAAA

Look at the response status and the ANSWER section. For a direct A record, a configured IPv4 address is expected. The NXDOMAIN status means that the queried DNS server reports that the name does not exist; NOERROR without the desired record is not equivalent to NXDOMAIN. We wrote more about this in our previous article.

If CDN proxying is enabled, the response may contain CDN addresses instead of the origin server’s IP. This is normal behavior for such a setup.

Next, open your website’s address over HTTPS in a browser. Verify that the correct website is displayed, the browser accepts the certificate, and navigation within the application does not redirect the user back to the old address.

Keep in mind that a successful DNS query only confirms receipt of a DNS response; the availability of the web server and the functionality of the application itself must be checked separately.

 

 

 

 

How Subdomains Affect SEO

According to Google’s documentation, Google can index and display in search results both pages on subdomains (e.g., blog.example.com) and pages in subfolders (e.g., example.com/blog/). Choosing one option over the other does not, in and of itself, provide a ranking advantage. Therefore, you should choose a structure based on your site’s architecture and ease of maintenance.

When launching a subdomain, you need to check its settings for search engine crawlers. For example, the robots.txt file on example.com does not apply to blog.example.com. And if the blog requires crawling restrictions, these should be specified in its own file: blog.example.com/robots.txt.

Test versions of the website require special attention. For instance, if staging.example.com hosts a working copy of the project that should not be visible to outsiders, access to it should be restricted via authentication or allowed only from specific IP addresses.

A ban in robots.txt isn’t suitable for this, since it restricts crawlers from accessing pages but doesn’t block the site from visitors and doesn’t guarantee that its URLs won’t appear in search results.

If a page needs to remain accessible to visitors but should not appear in search results, use the `noindex` directive. However, you must allow search bots to crawl the page; otherwise, they won’t be able to detect this directive.

Moving an existing section from a subfolder to a subdomain - or vice versa - requires preparation. Page URLs will change, so you’ll need to set up permanent redirects from the old URLs to the corresponding new ones and update internal links. It’s not worth undertaking such a migration solely in the hope of improving search rankings by changing the URL format.

 

 

 

 

What to Consider During Operation

Subdomains can share cookies, including for authentication. For example, if an application sets a cookie with the attribute Domain=example.com, the browser can send it to both the main domain and its subdomains. If this attribute is not specified, the cookie is sent only to the host that set it. Therefore, before setting up a single sign-on, you need to check which applications will have access to the cookies. This is especially true for subdomains connected to third-party platforms.

When a subdomain is no longer needed, it’s not enough to simply disable the application - you must also delete or modify the DNS record that directs visitors to that service; otherwise, it will continue to associate your address with a resource that is no longer in use.

On some external platforms, another user may register the vacated resource. If the DNS record remains unchanged, under certain conditions that user will be able to display their own pages at your address. This is called a subdomain takeover.

To avoid this situation, first remove the DNS record and account for the caching time of the previous response, and only then release the resource on the external platform. A simple list of subdomains - specifying the connected services and the employees responsible for them - helps maintain order within the team regarding this issue.

3v-Hosting Team

Author

3v-Hosting Team

The 3v-Hosting Team is made up of a dedicated group of engineers and operators who are all about building and maintaining the backbone of our services. Every day, we dive into the world of virtual and dedicated servers, handling everything from deployment and monitoring to troubleshooting real-world issues that pop up in production environments. Most of our articles stem from hands-on experience rather than just theory. We share insights on the challenges we face: performance hiccups, configuration missteps, networking intricacies, and architectural choices that impact stability and reliability. Our mission is straightforward – we want to share knowledge that empowers you to manage your projects with fewer surprises and a lot more predictability.

Configuring ACLs in Linux
Configuring ACLs in Linux

Configuring ACLs in Linux to manage access permissions for files and directories. The `setfacl` and `getfacl` commands, permission inheritance, ACL masks, diffe...

9 min