1

How do I redirect everything on www.site.com to site.com?

I use MUP to deploy my application to Digital Ocean. So far I am thinking of either adding a CNAME for www (couldn't get that to work), or add a meteor package that redirect server side (something like wizonesolutions:canonical), or SSH into the server and change NGINX manually.

What is the recommended approach for doing this?

Community
  • 1
  • 1
nilsi
  • 10,351
  • 10
  • 67
  • 79
  • Go to your DNS settings and set up redirect from www.site.com to site.com. This is most easiest and convenient way to do this. – LazyCat01 May 01 '16 at 15:03

2 Answers2

2

I forgot to mention that I use SSL (HTTPS). With that it's not possible to redirect with a CNAME in the domain settings.

I could not change the NGINX settings since every time I deployed, the container got replaced with a new one and MUP itself does not have any settings for this.

The recommended and very nice solution was to use wizonesolutions:canonical. Just remember to set ROOT_URL variable in the mup.js setup file to the desired URL (https://www.yourdomain.com or https://yourdomain.com)

nilsi
  • 10,351
  • 10
  • 67
  • 79
0

as of 2022, (mup v1.5.7), you can do as follow :

mup.js

  proxy: {
    domains: 'example.org,www.example.org',

    ssl: {
      letsEncryptEmail: 'hello@example.org',
      forceSSL: true,
    },

    nginxServerConfig: './nginx.conf',
  },

nginx.conf

# Start custom configuration: redirect www to non www
server_name example.org www.example.org;
if ($host = www.example.org) {
    return 301 https://example.org$request_uri;
}
# End of custom configuration

Nginx says "if is evil", but it's the only solution i've found to interoperate with the automatically generated nginx config.

you could even try to use a more generic approach :

server_name ~^.*$;
if ($host ~ ^www\.(?<domain>.+)$) {
  return  301 $scheme://$domain$request_uri;
}

Here, you won't have to maintain any website url.

LIIT
  • 496
  • 6
  • 16