Setting Up Your Domain on Cloudflare
Last updated: January 9, 2026
Setting up your domain on Cloudflare provides enhanced security, performance, and caching for your website. This guide covers essential configuration, including how to fix the common "Site not found" error when visitors access your site without the www prefix.
In This Guide
Deploy an Astro site from GitHub to Cloudflare Pages with a custom subdomain
Why do users see "Site not found" when www. is excluded?Set up your site so users can avoid typing in www.* to get to your page
How do I redirect from an old domain to a new one?Set up a redirect from an old site so customers don't bounce
What's the fastest way to set up www and non-www domains?Quick 5-step setup using Cloudflare Pages custom domains
How do I create a new Cloudflare website?
Follow these steps to deploy an Astro site from GitHub to Cloudflare Pages with a custom subdomain.
Step 1: Create and push your GitHub repo
Go to GitHub.com > Repositories. Create a new repository with a Node .gitignore. Open Claude Code and say “make this an Astro landing page”, and merge in the changes. Make sure your project builds successfully locally before deploying.
Step 2: Start creating a Cloudflare Pages application
- Go to Cloudflare Dashboard
- Navigate to Workers & Pages in the left sidebar
- Click Create Application
- Important: Pause on this page—don’t click the main buttons yet!
Step 3: Switch to Pages deployment
Look for the small text link that says “Looking to deploy Pages? Get started” and click it. This switches you from Workers to Pages deployment.
Step 4: Import your GitHub repository
- Click Import existing repository
- Connect your GitHub account if prompted
- Select your repository from the list
Step 5: Configure build settings
Update the build settings with these values:
| Setting | Value |
|---|---|
| Build command | npm run build |
| Build output directory | /dist |
Click Save and Deploy to start the deployment.
Step 6: Wait for deployment
Your site will deploy in a few minutes. You’ll see a success message: “Success! Your project is deployed to Region: Earth”.
Step 7: Add a custom domain
- Click Add a custom domain
- Click Set up domain
- Enter your subdomain in the format
<site>.silvermine.ai(e.g.,example.silvermine.ai) - Naming convention: Match the GitHub repo name—if the repo is
bob.silvermine.ai, usebob.silvermine.aias the custom domain - Click Activate domain
Step 8: Wait for DNS propagation
Your domain will be ready in approximately 5 minutes. Cloudflare automatically handles the DNS configuration for subdomains on domains already managed by Cloudflare.
Why do users see “Site not found” when www. is excluded?
When your website is configured to serve content from www.yourdomain.com, visitors who type just yourdomain.com (without the www) may see a “Site not found” error. This happens because:
- DNS records point to www only - Your hosting is configured for the www subdomain
- No redirect rule exists - There’s nothing telling Cloudflare to forward non-www traffic to www
- Different hostnames - Technically,
example.comandwww.example.comare different hostnames
The solution is to create a Page Rule that automatically forwards all non-www traffic to your www domain.
How to create a forwarding rule
-
Log in to your Cloudflare Dashboard
-
Select your domain from the list
-
In the left sidebar, click on Rules and then select Page Rules (or just “Rules” if you don’t see the submenu immediately)
-
Click the blue Create Page Rule button
-
Configure the rule with these settings:
| Field | Value |
|---|---|
| URL (Field 1) | yourdomain.com/* |
| Pick a Setting (Field 2) | Forwarding URL |
| Select Status Code (Field 3) | 301 - Permanent Redirect |
| Destination URL (Field 4) | https://www.yourdomain.com/$1 |
- Click Save and Deploy Page Rule
Understanding the configuration
yourdomain.com/*- The asterisk matches any path after your domain- 301 - Permanent Redirect - Tells browsers and search engines this is a permanent change (good for SEO)
$1in the destination - This captures whatever was after the slash and appends it to the new URL
Example redirects
| Visitor Types | Redirects To |
|---|---|
silvermine.ai | https://www.silvermine.ai |
silvermine.ai/contact | https://www.silvermine.ai/contact |
silvermine.ai/blog/post-title | https://www.silvermine.ai/blog/post-title |
Without the $1, all paths would redirect to just the homepage, breaking deep links.
How do I redirect from an old domain to a new one?
Silvermine.ai used to be www.silvermineai.com (sometimes we still send emails from our old domain because so much is connected to it). Here, we show how we set up a redirect from www.silvermineai.com to www.silvermine.ai.
Why this matters: If done incorrectly, your users will get a 404. For example, if there’s a link on the internet to www.silvermineai.com/about, they’ll land on a page that doesn’t exist anymore.
Part 1: Redirecting the old domain
Goal: Catch anyone typing your old domain name (with or without “www” or any path like “/about”) and send them to the new site.
The DNS setup (the “dummy” target)
First, create a DNS record to ensure Cloudflare catches the traffic on your old domain:
| Setting | Value |
|---|---|
| Type | A Record |
| Name | * (Wildcard) or @ (Root) |
| IPv4 Address | 192.0.2.1 (placeholder address) |
| Proxy Status | Proxied (Orange Cloud) |
Note: The IP
192.0.2.1is a documentation-reserved address. It doesn’t matter what it points to because Cloudflare will intercept the traffic before it reaches that IP.
The redirect rule
Create a Page Rule to catch everything on the old domain:
| Field | Value |
|---|---|
| URL | *silvermineai.com/* |
| Setting | Forwarding URL (301 Permanent Redirect) |
| Destination | https://www.silvermine.ai/$2 |
The $2 captures the path from the second wildcard, preserving deep links.
Part 2: Fixing the new root domain
Goal: Ensure first-time users who forget to type “www” on your new domain still get to the site.
| Field | Value |
|---|---|
| URL | silvermine.ai/* |
| Setting | Forwarding URL (301 Permanent Redirect) |
| Destination | https://www.silvermine.ai/$1 |
Summary of results
| User Types | Redirects To |
|---|---|
silvermine.ai | https://www.silvermine.ai |
silvermine.ai/about | https://www.silvermine.ai/about |
silvermineai.com | https://www.silvermine.ai |
silvermineai.com/contact | https://www.silvermine.ai/contact |
www.silvermineai.com | https://www.silvermine.ai |
www.silvermineai.com/services | https://www.silvermine.ai/services |
All paths are preserved, so existing links across the internet continue to work.
What’s the fastest way to set up www and non-www domains?
If your DNS is already managed by Cloudflare and you’re using Cloudflare Pages, there’s an even simpler approach than creating Page Rules. Cloudflare Pages can automatically create and manage your DNS records for both www.site.com and site.com.
Prerequisites
- Your domain’s DNS is already on Cloudflare
- You have a Cloudflare Pages project deployed
The 5-step setup
-
Set up your Pages build - Deploy your site to Cloudflare Pages (see the first section of this guide)
-
Remove existing DNS records - If you have any A, AAAA, or CNAME records for
@(root) orwww, delete them first. Cloudflare Pages will create the correct ones automatically. -
Navigate to Custom Domains - Go to Workers & Pages → Select your project → Custom Domains tab
-
Add both domains - Click Set up a custom domain and enter:
www.site.comsite.com
Add each one separately.
-
Wait for activation - Cloudflare will automatically create the required DNS records. This typically takes about 5 minutes.
Why this works
When you add custom domains through Pages, Cloudflare:
- Creates the appropriate DNS records pointing to your Pages deployment
- Handles SSL certificate provisioning automatically
- Sets up the redirect from non-www to www (or vice versa) based on which domain you added first
This method is faster and less error-prone than manually creating DNS records and Page Rules, especially for new sites.
Looking for expert guidance? Schedule a free consult:
Book a Free Consultation