Gazebo
    ServicesAgentsDocsSpecWritingPricing
    Log inSign up
    Log in
    GazeboWorkflowsCloudflareHow to Redirect www to Apex Domain in Cloudflare

    Workflow

    How to Redirect www to Apex Domain in Cloudflare

    Permanently redirect www traffic to your apex domain.

    Last updated June 2026

    That's 4 steps.

    Describe it once — Gazebo generates a plan, you approve it, it runs.

    "Add a Cloudflare redirect rule to redirect www to the apex domain with a 301"

    Let Gazebo handle this

    What you're doing and why it's painful

    If someone visits www.yourdomain.com, they should land on yourdomain.com — the same page, no dead end. Without a redirect, you have duplicate content (bad for SEO) and confused visitors.

    Cloudflare can handle this entirely at the edge, before the request ever hits your server. The pain: the redirect lives in a different part of the dashboard depending on your Cloudflare plan, the SSL setting has to be right or you'll get redirect loops, and getting the $1 wildcard wrong means your redirect strips the path.

    Prerequisites

    • Your domain is using Cloudflare DNS (orange cloud icon)
    • You have access to the Cloudflare dashboard for that zone

    Option A — Redirect Rules (recommended, free plan)

    Cloudflare's Redirect Rules are the modern replacement for Page Rules. They work on all plans including free.

    1. Log in to Cloudflare dashboard
    2. Select your domain
    3. Go to Rules → Redirect Rules
    4. Click Create rule
    5. Name it: Redirect www to apex
    6. Under When incoming requests match..., set:
      • Field: Hostname
      • Operator: equals
      • Value: www.yourdomain.com
    7. Under Then..., set:
      • Type: Dynamic
      • Expression: concat("https://yourdomain.com", http.request.uri.path)
      • Status code: 301
    8. Click Deploy

    The http.request.uri.path variable preserves the path — so www.yourdomain.com/pricing correctly redirects to yourdomain.com/pricing.

    Option B — Page Rules (older method, still works)

    1. Go to Rules → Page Rules
    2. Click Create Page Rule
    3. URL: www.yourdomain.com/*
    4. Setting: Forwarding URL
    5. Status: 301 - Permanent Redirect
    6. Destination: https://yourdomain.com/$1
    7. Click Save and Deploy

    The $1 captures whatever comes after www.yourdomain.com/ and appends it to the destination. www.yourdomain.com/pricing → yourdomain.com/pricing.


    Step 2 — Check your SSL/TLS setting

    A common cause of redirect loops: your SSL setting is too low.

    1. Go to SSL/TLS → Overview
    2. Make sure it's set to Full or Full (strict) — not Flexible

    With Flexible SSL, Cloudflare connects to your origin over HTTP, which can cause loops when your origin also tries to redirect HTTP to HTTPS.

    Step 3 — Verify the DNS entry for www

    Make sure your www record exists in Cloudflare DNS and is proxied (orange cloud):

    1. Go to DNS → Records
    2. You should see a www CNAME or A record pointing to your domain or IP
    3. The cloud icon should be orange (proxied) — if it's grey (DNS only), Cloudflare's redirect rules won't apply

    If there's no www record, add one:

    • Type: CNAME
    • Name: www
    • Target: yourdomain.com
    • Proxy: on (orange cloud)

    Testing the redirect

    curl -I https://www.yourdomain.com
    

    Look for HTTP/2 301 and location: https://yourdomain.com/ in the response headers. If you see a 200 instead, the redirect hasn't deployed yet or there's a DNS/proxy issue.


    Common errors and gotchas

    Redirect loop Almost always caused by Flexible SSL. Switch to Full or Full (strict) under SSL/TLS settings.

    www.yourdomain.com not resolving at all No www DNS record exists. Add a proxied CNAME pointing www to your apex domain.

    Path not preserved — redirect lands on homepage regardless of URL Using $1 in Page Rules but the wildcard isn't matching. Make sure your Page Rule URL is www.yourdomain.com/* (with the /* at the end). Alternatively, switch to Redirect Rules which use the expression syntax above.

    Redirect not showing as 301 Cloudflare may cache the first response. Wait a few minutes and test in incognito to avoid browser cache. Or use curl which ignores browser caching.

    Skip the manual steps.

    Describe it once — Gazebo generates a plan, you approve it, it runs.

    "Add a Cloudflare redirect rule to redirect www to the apex domain with a 301"

    Let Gazebo handle this
    ← All Cloudflare workflowsAll workflows
    Gazebo

    IAM for AI agents. Scoped credentials, access policies, and audit trails — without rotating keys.

    Product

    • Pricing
    • Status

    Explore

    • Services
    • Agents
    • Workflows
    • Integrations

    Content

    • Writing
    • Topics
    • Blog
    • Docs

    Free Tools

    • Scanner

    Company

    • About
    • [email protected]
    • [email protected]

    © 2026 Gazebo. All rights reserved.

    PrivacyTermsSecurity