How do I redirect www to non-www?

(flexihack) #1

I have read several posts on meta discourse but couldn’t find the solution. I tried to follow this post:

But it couldn’t help because it says “In this tutorial we’ll show how to redirect and to

right now, I’m looking for a way to redirect from to Anyone can help?

When installing discourse with lets encrypt any way to have it redirect?
(Jeff Atwood) #4

You need to follow the howto you linked. It is exactly the same process, only the URLs are slightly different.

(flexihack) #5

@codinghorror I do not get this part:

path: /etc/nginx/conf.d/discourse_redirect_1.conf
    contents: |
      server {
        listen 80;
        return 301 $scheme://$request_uri;

First off all, what do I change the “discourse_redirect_1.conf” to? If I want to redirect from to then for server_name what do I put? with or without www? Samething go to the last line. Thanks

(Arpit Jalan) #10

You do not need to change the file name, discourse_redirect_1.conf will work fine.

If you want to redirect to then in server_name put and in last line put return 301 $scheme://$request_uri;

(Tomo Vukasović) #13

This is not working for me. I tried every possible configuration…restart, rebuild and nothing. I am running docker on digital ocean. One thing that I noticed is that www was not working at all after the discourse installation, only non-www was accessible. I fixed this with CNAME, but still I can not redirect either way from non-www to www or other way around. Problem is of course with cookies I have to login separately into each version of the site.

(charles) #14

For me, I use A record for www (instead of CNAME) and reverse the configuration in this guide so my choice was going from non-www to www. Maybe this will work better for you?

(Kane York) #15

Again, don’t put a CNAME on the root domain. Two A or AAAA records to the same IP will do fine for redirecting.

For others chancing on this thread:


Why shouldn’t you use CNAME for for domain?

(Michael - #17

A CNAME replaces all records for the domain, not just the A record.
But a domain needs SOA, NS and MX records, and you cannot have any of those if you have a CNAME.

We don’t recommend using the naked domain for hosting anyway, it’s better to do it the other way around: redirect the domain to www.

For our hosting, we set up a generic service for that at, but it’s available to be used by anyone. We automatically provision LetsEncrypt certificates so it’s usable with https as well.