Get the latest updates, in-depth tutorials, and exclusive resources on themes, templates, and code. Stay ahead with our expert insights—join our Telegram channel today!

How to Add a Subdomain in GitHub Pages

Learn how to add a custom subdomain to GitHub Pages with DNS configuration and CNAME setup.

GitHub Pages is a powerful tool for hosting static websites, and adding a custom subdomain (e.g., blog.example.com) can give your site a professional touch.

GitHub Pages Custom Subdomain Setup Guide
Step-by-step guide to configure a custom subdomain on GitHub Pages.

Whether you're a beginner or an expert, this guide will walk you through the steps to successfully configure a subdomain for your GitHub Pages site.


Why Use a Custom Subdomain?

  • Enhances branding and professionalism.
  • Provides better SEO optimization.
  • Allows multiple sites under one domain (e.g., docs.example.com, portfolio.example.com).
  • Offers flexibility in managing different projects.

Prerequisites

Before you start, ensure that:

  • You have a GitHub Pages site already set up.
  • You own a custom domain (e.g., example.com).
  • You have access to your DNS settings via your domain registrar (e.g., Namecheap, Cloudflare, GoDaddy).

Step 1: Set Up GitHub Pages

  1. Open your GitHub repository.
  2. Go to Settings > Pages.
  3. Under Build and Deployment, select the correct branch (e.g., main or gh-pages).
  4. Click Save and note the generated GitHub Pages URL (yourusername.github.io).

Step 2: Configure Your DNS Settings

To point your subdomain to GitHub Pages, follow these steps:

For a Subdomain (e.g., blog.example.com):

  • Open your DNS settings with your domain registrar.

  • Add a CNAME record with the following details:

    Type Name Value TTL
    CNAME blog your-github-username.github.io Auto

📌 Example: If your site is hosted at yourusername.github.io, and you want blog.example.com as your subdomain, your CNAME should point blog to yourusername.github.io.


Step 3: Add a CNAME File in Your GitHub Repository

  1. In your GitHub repository, go to the root directory.
  2. Create a new file named CNAME (no file extension).
  3. Inside the file, type your subdomain (e.g., blog.example.com).
  4. Commit and push the file to your repository.

Step 4: Verify and Enable HTTPS

  • Wait for DNS propagation (this may take a few minutes to hours).
  • Visit GitHub Settings > Pages to check if your subdomain is recognized.
  • Enable Enforce HTTPS for security and better SEO performance.

Troubleshooting Tips

Issue: My Subdomain Isn't Working

✅ Ensure your CNAME record is correctly configured. ✅ Check if the CNAME file in your repository has the correct subdomain. ✅ Wait for DNS propagation (use DNS Checker to verify). ✅ Clear your browser cache and retry.

Issue: SSL Certificate Not Available

✅ Make sure you enabled Enforce HTTPS in GitHub Pages settings. ✅ Wait for GitHub to generate the SSL certificate (it can take a few hours). ✅ Remove any conflicting SSL settings from your domain registrar.


Conclusion

Setting up a custom subdomain on GitHub Pages is a straightforward process that enhances your website's professionalism and usability. By following these steps, you can easily configure a subdomain and optimize your GitHub Pages site for branding and SEO.

🚀 Now, try it out and let us know how it goes!

My name is It Is Unique Official, and I write news articles on current threats and trending topics. I am based in Parbhani, Maharashtra, India.

Post a Comment

Please avoid spamming in the comment section; all comments are moderated by the admin for quality and relevance.