boilerplate-nutella
boilerplate-nutella copied to clipboard
non-www redirect
Implement a non-www redirect feature on the server and give an option to choose between with www
or 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);