How do I setup an alias so that www.mydomain.com permanently redirects to mydomain.com using Zeit now CLI?
I tried now dns add mydomain.com www CNAME mydomain.com
but it does not work.
It seems * CNAME alias.zeit.co
is prioritized over www CNAME
.
First, you need to add an alias pointing your deployment to your root domain.
now alias my-deployment-url.now.sh example.com
Then you need to add a redirect. Since this is not possible with DNS, you need to have some web server emit a 301/302 redirect. In this case, we'll make a new deployment.
now -e REDIRECT_URL=https://example.com now-examples/redirect
Now that we have this new "redirect" deployment, we'll alias it as www like so:
now alias https://redirect-otytioldup.now.sh www.example.com
See the docs for more info.