Making 'www' work with Discourse

Hi there, I would like to make sure the www subdomain redirects the users to the actual Discourse install. I feel like this needs to be the case to ensure I don’t lose visitors. Most people don’t leave out the ‘www’ when visiting websites.

3 Likes

You need to add an A record in your DNS settings at your registrar for www pointing to the server’s IP. The same one you are currently pointing the domain.com A record to.

1 Like

Will this cause issues when the user visits using the www version? Discourse is set to not have the www included.

1 Like

No because the user will be redirected. It won’t serve the same site under multiple domains.

3 Likes

You want these guides. I used them for the same exact purpose:

4 Likes

Are you saying adding the A record for ‘www’ isn’t enough? I read through those articles.

My site would get a nasty message on the browser without registering a certificate for both “sub-domains”.

1 Like

I’ve just set up Discourse on a Digital Ocean droplet. For step 2, editing discourse.conf, does that require nginx to be installed? I’m not certain but I don’t think my droplet has nginx installed and I’m at a loss with how to install it.

I think this guide explains that part:

https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247/294

1 Like

Yes adding an a record for www aimed at the same IP will be adequate to redirect the traffic.

You don’t need to do anything outlined in those other guides, an A record pointed to the IP will suffice for a simple redirect.

Try not to complicate your install unless absolutely necessary.

3 Likes

Will this be enough to avoid a NET::ERR_CERT_COMMON_NAME_INVALID browser error though? If I install discourse on the www subdomain, accessing the site with https://example.com gives me that error. It only works if you use https://www.example.com.

That’s why you want to use a redirect, discourse can’t be served from multiple URLs.

Pick one, redirect the other.

1 Like

I have a similar issue and using a URL redirect record at the DNS level doesn’t solve the problem for me.

I installed Discourse using the hostname ‘www.example.com’ and the following DNS records:

A Record             host:WWW      value:my_server_ip
CNAME                host:@        value: www.example.com
URL Redirect Record  host:@        value:https://www.example.com

If I then use SSL Server Test (Powered by Qualys SSL Labs) to check the URL https://example.com without the WWW I get a Certificate name mismatch and in my browser a NET::ERR_CERT_COMMON_NAME_INVALID error.

Apologies again if I’m missing something obvious here, networking isn’t my strong point!

1 Like

Hence why I posted those links. I’d love it to be as simple as a DNS change. It didn’t seem to be that simple to me either. To work via https I had to ensure that a cert was being registered for both addresses. To achieve that use one of the guides I posted above. The other guide allows you to perform a redirect.

Users are very unlikely to specify the protocol when typing in a URL. If you’re really worried about it you can just use Cloudflare for DNS and a simple page rule.

1 Like

Yeah, I ‘moved’ my domain (well I just chose to cut off the www) which is why I had to serve existing links already on sites I didn’t control referring to my old domain with https. That might explain why in my case I had no choice but to do the full job.

So what I think you are saying is, if you are just happy to have someone type in www.example.com and for it to be redirected to https://example.com requires only a DNS change?

However, if for any reason you want https://www.example.com to work (in my case I did because such links were already ‘out there’) you have to follow the provided guides

Or just use a page rule as stated above. It will front the domain using a wildcard cert and redirect the traffic seamlessly.

All with zero additional complexity on the Discourse server.

1 Like

What’s a page rule?

I’m intending to follow How To Install Discourse Behind Nginx on Ubuntu 14.04 | DigitalOcean to install Nginx on my Digital Ocean droplet and then apply the rules listed in “step 2” to redirect to the correct domain. I think this should work! I’ll try it tomorrow and see if it allows me to redirect all combinations of https://www., http://www, http://domain.com, https://domain.com to my discourse hostname which the Lets Encrypt cert which is is https://www.domain.com.

We’ll see!

@Erik_Manger, DNS-based solutions didn’t work for me with SSL. I used the first link provided by @merefield and it works well.

Did you need to install Nginx in-front of Discourse to get this to work? On my Digital Ocean droplet the path “/etc/nginx/” used in the additional hooks doesn’t exist.