Is it possible to redirect from now www to www using mup js for EC2

Hi everyone,

I have deployed an app on AWS EC2 instance. Now I want it to get redirect to www.appname.com when user type appname.com in the url.

I am not able to figure out how to do it.

Here is something I found while searching regarding this

  1. Using Wizonesolutions Package found at StackOverflow
  2. Using this : https://blog.qbatch.com/lets-encrypt-ssl-nginx-mup-deployment-meteor-3aea28b6dbd9

Please let me know if there is any other possible way to do the same. Any help would be greatly appreciated.

This part of our app is quite old so there are probably better ways to do it (at least by now) but the way i did it is right within the application’s server code:

WebApp.connectHandlers.use(function (req, res, next) {
    if (req.headers && req.headers.host !== Meteor.settings.mainUrl && req.headers.host.slice(0, 9) !== 'localhost') {
        res.writeHead(301, {
            Location: 'https://' + Meteor.settings.mainUrl + req.originalUrl
        });
        res.end();
    } else {
        next();
    }
});

where Meteor.settings.mainUrl is something like www.yourdomain.com

this piece of code also allows you to point multiple Domains to your app and have them redirect to whatever main domain you want to use.

Thanks @chris74656, will try this and update you

Hi @chris74656, Could you share the changes that needs to be done in mup.js?