You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将www域名重定向至根域名?Zeit Now CLI配置问题

Hey there, let's break down your questions and fix that redirect issue you're facing!

1. 如何将www域名重定向至根域名(@)?

The approach depends on where you're managing your DNS and hosting, but here are the most common ways:

  • DNS Provider Direct Setup: Most DNS services offer a "URL Redirect" or "Forwarding" feature. Just locate this option, select www.yourdomain.com, set the redirect type to 301 Permanent, and point it to yourdomain.com.
  • Zeit Now/Vercel-Specific: Since you're working with Zeit Now, the cleaner way is to use its alias system to handle the redirect directly, which ties into your second question below.
2. 如何通过Zeit Now CLI设置别名,使www.mydomain.com永久重定向至mydomain.com?

You're right about the wildcard CNAME record (* CNAME alias.zeit.co) taking precedence—it matches all unspecified subdomains, including www, so your explicit www CNAME gets ignored. Let's fix this step by step:

Step 1: Resolve the DNS Conflict

First, you have two options here:

  • Remove the wildcard CNAME (if you don't need it for other subdomains):
    now dns remove mydomain.com * CNAME
    
  • Keep the wildcard record: Skip deleting it, but we'll use Zeit Now's alias redirect feature instead of DNS CNAME to make the www redirect work.

Step 2: Set Up the Root Domain Alias

Ensure your root domain is linked to your Zeit Now deployment first:

# Replace <your-deployment-id> with your actual deployment ID (find it via `now list`)
now alias set <your-deployment-id> mydomain.com

If you haven't added your domain to Zeit Now yet, run now domains add mydomain.com first—it will auto-configure the necessary root domain DNS records (A/ALIAS) for you.

Step 3: Configure the www Redirect

Now set up the www alias with a permanent redirect to the root domain:

now alias set <your-deployment-id> www.mydomain.com --redirect mydomain.com --permanent

The --permanent flag ensures this is a 301 redirect, which is best for SEO and browser caching.

Step 4: Verify the Setup

Wait 1-5 minutes for DNS changes to propagate, then visit www.mydomain.com. You should be automatically redirected to mydomain.com, and checking your browser's network tab will show a 301 status code confirming the permanent redirect.

内容的提问来源于stack exchange,提问作者Joon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:26:24