boilerplate-nutella icon indicating copy to clipboard operation
boilerplate-nutella copied to clipboard

non-www redirect

Open allanesquina opened this issue 6 years ago • 0 comments

Implement a non-www redirect feature on the server and give an option to choose between with wwwor not. Here an example:

...
function wwwRedirect(req, res, next) {
    if (req.headers.host.slice(0, 4) === 'www.') {
        var newHost = req.headers.host.slice(4);
        return res.redirect(301, req.protocol + '://' + newHost + req.originalUrl);
    }
    next();
};

app.use(wwwRedirect);

allanesquina avatar Jan 19 '19 00:01 allanesquina