Skip to content

Custom domain

After the first deploy you’ll have a host-generated URL like my-site.pages.dev, my-site.vercel.app, or my-site.netlify.app. Pointing your real domain at it is two changes — one on the host, one at your DNS provider.

In astro.config.mjs, set the production site:

astro.config.mjs
export default defineConfig({
site: 'https://yourdomain.com',
// …
});

And in src/config/site.ts:

url: "https://yourdomain.com", // no trailing slash

These two values feed canonical URLs, the sitemap, OG tags, and any place the build needs to generate absolute URLs. Get them right before you submit your site to Google Search Console — incorrect canonicals are a pain to walk back.

Redeploy after changing.

Pick the section that matches your host:

  1. Project → Custom domains → Set up a custom domain.
  2. Enter yourdomain.com.
  3. Cloudflare auto-detects whether your domain is on Cloudflare DNS:
    • On Cloudflare DNS: it sets the CNAME automatically. Done.
    • Elsewhere: Cloudflare gives you a CNAME target like my-site.pages.dev. Add a CNAME at your DNS provider — see Step 3.
  4. Add www.yourdomain.com too (separately) so both work.
  1. Project → Settings → Domains → Add.
  2. Enter yourdomain.com.
  3. Vercel asks: which version should be the canonical?
    • Apex (yourdomain.com) — A record points to Vercel’s IPs.
    • Subdomain (www.yourdomain.com) — CNAME to cname.vercel-dns.com.
  4. Add the other variant too (with a 301 redirect to the canonical).
  1. Site → Domain management → Add custom domain.
  2. Enter yourdomain.com.
  3. Netlify gives you either an ALIAS/ANAME record (for the apex) or a CNAME (for subdomains).
  4. Add both yourdomain.com and www.yourdomain.com; configure the redirect in Domain management → HTTPS settings.

Where your DNS lives depends on where you bought the domain. Common providers:

  • Cloudflaredash.cloudflare.com → your domain → DNS.
  • Namecheap — Domain List → Manage → Advanced DNS.
  • Google Domains / Squarespace — DNS → Custom records.
  • Porkbun — Manage → DNS records.

For most setups, you’ll add:

TypeNameValue
A@(Vercel/Netlify will give you specific IPs)
ALIAS@my-site.pages.dev (Cloudflare/Netlify supported; not all providers)

If your DNS provider supports ALIAS/ANAME, prefer that — it’s more flexible than A records.

TypeNameValue
CNAMEwwwmy-site.pages.dev

After saving, DNS propagation takes anywhere from 30 seconds to 24 hours. Most major providers update within 5 minutes.

Terminal window
dig yourdomain.com
dig www.yourdomain.com
# Or in a browser:
curl -I https://yourdomain.com

Look for a 200 and a header like cf-ray: (Cloudflare) or x-vercel-id: (Vercel) — that confirms requests are hitting your host.

Every host listed above issues a Let’s Encrypt certificate automatically. After DNS resolves, the cert lands within a few minutes. You don’t have to do anything.

If you see a “this site is not secure” warning after DNS resolves, wait 10 minutes. If it persists past 30 minutes:

  • Cloudflare: check that SSL/TLS mode is set to Full (not Flexible).
  • Vercel / Netlify: re-add the domain on the dashboard — that triggers a cert refresh.

Pick one. The other should 301-redirect to it.

  • www.yourdomain.com is canonical historically — easier with CNAMEs and works on every DNS provider.
  • yourdomain.com (apex) is shorter and “modern” — requires ALIAS/ANAME or A records.

Both are fine. Just don’t run them as two separate sites — that splits Google’s PageRank.