Default platform subdomains like my-project.pages.dev or username.github.io are fine for initial staging and internal proofs of concept. However, running a production digital product, SaaS landing page, or corporate blog demands a branded custom domain (e.g., flovo.in or blog.flovo.in).

Connecting a custom domain to a static hosting platform requires coordinating domain registrars, DNS authoritative nameservers, edge CDN routing, and automated SSL/TLS provisioning. A minor misconfiguration can cause downtime, browser security warnings, or broken canonical indexing in search engines.

In this practical guide, we break down the architecture of custom domain mapping, resolve the apex versus subdomain dilemma, provide step-by-step instructions for major static hosting platforms, and outline how to verify your deployment using command-line diagnostic tools.


Architectural Overview of Domain Mapping

When a visitor requests your domain, a chain of independent systems works together to route the request:

+---------------------------------------------------------------------------------+
|                       Domain Mapping Request Path                               |
+---------------------------------------------------------------------------------+
|                                                                                 |
| 1. Domain Registrar (e.g., Namecheap, Cloudflare Registrar, GoDaddy)            |
|    - Holds domain registration and points to Authoritative Nameservers          |
|    - Example: NS ns1.cloudflare.com, NS ns2.cloudflare.com                     |
|                                                                                 |
| 2. DNS Zone Manager (Authoritative DNS)                                         |
|    - Resolves queries for your domain records (A, AAAA, CNAME)                  |
|    - Maps `blog.flovo.in` ---> `flovo-blog.pages.dev`                          |
|                                                                                 |
| 3. Edge CDN / Hosting Provider (e.g., Cloudflare Pages, S3+CloudFront)           |
|    - Receives incoming HTTP/HTTPS request                                       |
|    - Validates Host header against configured custom domains                    |
|    - Terminates TLS using auto-provisioned certificate                          |
|    - Serves static assets from edge cache                                       |
|                                                                                 |
+---------------------------------------------------------------------------------+

The Apex vs Subdomain Strategy

Before creating DNS records, you must choose your canonical address structure:

  • Apex Domain (Root / Naked Domain): example.com
  • Subdomain: www.example.com or blog.example.com

The RFC 1912 CNAME Apex Dilemma

A common stumbling block is attempting to point an apex domain (example.com) directly to a hosting provider using a CNAME record.

According to RFC 1912 (Section 2.4), a CNAME record cannot coexist with any other record type for the same node. Because every domain apex requires NS and SOA records, placing a standard CNAME record at the root domain breaks email routing (MX) and zone delegation.

Modern Solutions to the Apex Dilemma

  1. CNAME Flattening (Cloudflare): Cloudflare allows you to create a CNAME at the apex. When external resolvers query your domain, Cloudflare dynamically resolves the target hostname and returns standard A and AAAA IP records, adhering strictly to RFC specifications.
  2. ALIAS / ANAME Records (DNSimple, Namecheap, Route 53): Similar to CNAME flattening, the authoritative nameserver performs the lookup on the backend and synthesizes A records.
  3. Canonical Subdomain with 301 Redirect: Many organizations designate www.example.com as the canonical website, configuring a 301 redirect from example.com to www.example.com.

Configuration Guide for Major Static Hosts

Cloudflare Pages provides the smoothest custom domain setup, especially if your DNS is also managed on Cloudflare.

Step 1: Add Custom Domain in Cloudflare Pages

  1. In the Cloudflare Dashboard, navigate to Workers & Pages.
  2. Select your project and click the Custom domains tab.
  3. Click Set up a custom domain.
  4. Enter your desired domain (e.g., blog.example.com or example.com).
  5. Click Continue.

Step 2: Automatic DNS Configuration

  • If your domain’s DNS is managed within the same Cloudflare account, Cloudflare automatically provisions the CNAME record in your DNS zone and immediately begins issuing the SSL certificate.
  • If your DNS is managed by an external registrar (e.g., GoDaddy, Route 53), Cloudflare displays the exact CNAME target you must add to your external DNS manager:
Type:  CNAME
Name:  blog
Value: <your-project>.pages.dev
TTL:   Auto (or 300)

Within a few minutes, Cloudflare validates the CNAME record, issues an SSL certificate through Google Trust Services or Let’s Encrypt, and marks the domain as Active.


Scenario 2: GitHub Pages

To connect a custom domain to a repository hosted on GitHub Pages:

Step 1: Add the CNAME File

In your repository’s root (or inside the static/ folder for Hugo so it is copied into public/CNAME during build), create a file named CNAME containing only your domain name:

blog.example.com

Alternatively, navigate to Repository Settings > Pages > Custom domain, enter your domain, and save. GitHub will commit the CNAME file automatically.

Step 2: Configure DNS Records

For a Subdomain (blog.example.com or www.example.com): Add a single CNAME record at your DNS provider:

Type:  CNAME
Name:  blog
Value: <your-username>.github.io.

For an Apex Domain (example.com): Point your apex domain to GitHub’s Anycast IP addresses using four A records:

Type: A    Name: @    Value: 185.199.108.153
Type: A    Name: @    Value: 185.199.109.153
Type: A    Name: @    Value: 185.199.110.153
Type: A    Name: @    Value: 185.199.111.153

And optionally four IPv6 AAAA records:

Type: AAAA   Name: @   Value: 2606:50c0:8000::153
Type: AAAA   Name: @   Value: 2606:50c0:8001::153
Type: AAAA   Name: @   Value: 2606:50c0:8002::153
Type: AAAA   Name: @   Value: 2606:50c0:8003::153

Step 3: Enforce HTTPS

Once DNS resolves to GitHub, the Enforce HTTPS checkbox in your GitHub repository settings becomes clickable. Check this box to guarantee all HTTP traffic is automatically upgraded to HTTPS.


Configuring Canonical 301 Redirects

To prevent search engines from indexing both example.com and www.example.com as duplicate content, configure an explicit canonical redirect.

If your canonical domain is example.com, configure a redirect rule on your DNS or edge provider:

Incoming Request: http://www.example.com/* or https://www.example.com/*
Status Code:      301 Moved Permanently
Target Location:  https://example.com/$1

In Cloudflare, this is configured via Rules > Redirect Rules:

  • Rule Name: Canonical Redirect www to Apex
  • Filter: http.host eq "www.example.com"
  • Action: Dynamic Redirect to concat("https://example.com", http.request.uri.path) with status code 301.

Verifying Domain and SSL Configuration via Terminal

Never rely solely on your local desktop browser to verify DNS changes, as browser and OS-level DNS caches can show stale results. Use command-line utilities:

1. Verify DNS Resolution

# Check resolution via Cloudflare Resolver
dig @1.1.1.1 blog.example.com CNAME +short

# Verify resolved IP addresses
dig @1.1.1.1 blog.example.com A +short

2. Verify HTTP to HTTPS 301 Redirect

curl -I http://blog.example.com

Expected output:

HTTP/1.1 301 Moved Permanently
Location: https://blog.example.com/

3. Verify TLS Handshake and Certificate Subject

openssl s_client -connect blog.example.com:443 -servername blog.example.com < /dev/null 2>/dev/null | openssl x509 -noout -subject -dates -issuer

Expected output:

subject=CN=blog.example.com
notBefore=Oct 20 00:00:00 2026 GMT
notAfter=Jan 18 23:59:59 2027 GMT
issuer=C=US, O=Let's Encrypt, CN=R3

Production Launch Checklist

  • Apex vs Subdomain strategy selected and documented.
  • CNAME or A records created at authoritative DNS provider.
  • Custom domain verified in hosting platform dashboard.
  • SSL certificate issued and verified with no browser warnings.
  • 301 canonical redirects active (www to apex or apex to www).
  • Static generator baseURL updated to reflect the canonical custom domain.
  • All internal links and canonical meta tags verified relative to the custom domain.