Using Subdomains with Github Pages for Better Site Organization

GitHub Pages is a popular platform for hosting static websites directly from a GitHub repository. Many users want to organize their sites better by using subdomains, which can help separate different sections or projects under a main domain. This article explores how to use subdomains with GitHub Pages to enhance your site organization.

What Are Subdomains?

Subdomains are additional sections of a main domain, created to organize content more effectively. For example, in blog.example.com, “blog” is a subdomain of the main domain example.com. Subdomains can point to different servers or hosting services, making them ideal for separating different parts of a website.

Using Subdomains with GitHub Pages

While GitHub Pages primarily hosts sites under username.github.io or project pages, you can also set up custom subdomains to point to your GitHub Pages sites. This process involves configuring DNS records and updating your repository settings.

Step 1: Choose Your Subdomain

Select a subdomain that reflects the content or purpose of that section of your site. For example, docs.yourdomain.com for documentation or blog.yourdomain.com for a blog.

Step 2: Configure DNS Records

Log in to your domain registrar’s DNS management panel. Create a new CNAME record for your subdomain that points to your GitHub Pages URL, which is usually yourusername.github.io. For example:

  • Type: CNAME
  • Name: blog (or your chosen subdomain)
  • Value: yourusername.github.io

Step 3: Update Your GitHub Repository

In your GitHub repository for the site, create or update a file named CNAME in the root directory. Inside this file, add your subdomain, such as blog.yourdomain.com. Commit and push the changes.

Benefits of Using Subdomains

  • Better organization of different site sections
  • Improved user experience by segmenting content
  • Enhanced SEO for specific content areas
  • Flexibility to host different projects separately

Using subdomains with GitHub Pages is a powerful way to organize your website more effectively. By following these steps, you can create a professional and well-structured online presence that is easy to navigate and maintain.