# 如何启用 www 子域名

**URL:** https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808
**Category:** Self-hosting
**Created:** [2018年九月9日 23:08 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808 "2018-09-09T23:08:49Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Bblue](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bblue/32/80155_2.png) [@Bblue](https://meta.discourse.org/u/Bblue)
#### Post date: [2018年九月9日 23:08 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/1 "2018-09-09T23:08:49Z")

</div>

Hi guys, I want to know how can I enable “www” ([https://www.mydomain.com](https://www.mydomain.com)), but keep [mydomain.com](http://mydomain.com) as primary hostname. I mean, redirecting from “www” to non-“www”, using let’s encrypt.

I found a guide about install nginx after to install discourse from docker, but I’m very noobie, so can anyone help me and explain me all steps. My forum is empty so no problem to reinstall everything if it’s necessary.

ps. Ubuntu 18, digital ocean vps droplet.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年九月10日 20:48 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/3 "2018-09-10T20:48:28Z")

</div>

I’m pretty sure that wasn’t what he was asking at all @pfaffman .. he was asking “how do I automatically redirect visitors to the non-www version of my domain”.

`example.com`  
`www.example.com`

This is most easily done via the DNS controls where you purchased your domain name from. If your DNS provider doesn’t support redirection, you’re stuck implementing redirects in your webserver.

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [2018年九月10日 21:09 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/4 "2018-09-10T21:09:00Z")

</div>

We offer a [free service](https://www.forcewww.com) to do it the other way around (and that page also gives some reasons why that is a better idea).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2018年九月10日 23:45 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/5 "2018-09-10T23:45:40Z")

</div>

> [@codinghorror](#):
>
> “how do I automatically redirect visitors to the non-www version of my domain”.

If he points both domains to his Discourse server and he has https on his site he’s fine as long as people hit the http version. Then it’ll do the redirect to `https://example.com` as desired.

If what he wants is also to have `https://www.example.com` to redirect to the bare domain, then the instructions I link to provide at least a hint of how to accomplish that. (I’m pretty sure that I did that recently.)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年九月11日 00:04 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/6 "2018-09-11T00:04:08Z")

</div>

No, that topic is about multisite and multiple domains hosted on the same machine, that is

`example.com`  
`foo.org`  
`bar.net`

---

<div class="post-metadata">

### Author: ![Bblue](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bblue/32/80155_2.png) [@Bblue](https://meta.discourse.org/u/Bblue)
#### Post date: [2018年九月18日 16:59 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/7 "2018-09-18T16:59:32Z")

</div>

hi again, well, I just created an A record “www” pointing to my droplet’s IP, and apparently it worked fine,

can you give me a feedback if it’s working?

Basically I want force www to non-www, and https: [clic here](http://www.kamehouse.net)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2018年九月18日 17:42 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/8 "2018-09-18T17:42:43Z")

</div>

[http://www.kamehouse.net/](http://www.kamehouse.net/) – works as you wish  
[https://www.kamehouse.net/](https://www.kamehouse.net/) – is a certificate error

It’s not that likely that someone will stick `https` in front of the www, so you’re probably in good shape.

---

<div class="post-metadata">

### Author: ![Bblue](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bblue/32/80155_2.png) [@Bblue](https://meta.discourse.org/u/Bblue)
#### Post date: [2018年九月18日 21:16 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/9 "2018-09-18T21:16:09Z")

</div>

edit, can I get a certificate from cerbot just for www w/o install discourse again?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [2018年十月2日 23:34 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/10 "2018-10-02T23:34:54Z")

</div>

Why not just set up a redirect? There’s no value in having your instance published under two discrete fqdn.

Get your domain off of digitaloceans DNS, and use your domain registrar’s tools to redirect any additional subdomains to the main URL. This doesn’t need to touch your discourse install at all.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年三月29日 19:57 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/11 "2019-03-29T19:57:25Z")

</div>

I noticed this when you posted it, but today was the first time I had reason to use it. Thanks very much!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2022年五月30日 17:57 UTC](https://meta.discourse.org/t/how-can-i-enable-www-subdomain/96808/12 "2022-05-30T17:57:57Z")

</div>


