Redirect www. to non-www (for SEO)

This commit is contained in:
Gaël Métais
2015-05-25 15:01:21 +02:00
parent a97dcc5efb
commit 22ab7515fb
2 changed files with 14 additions and 0 deletions
@@ -0,0 +1,12 @@
var wwwRedirectMiddleware = function(req, res, next) {
'use strict';
// Redirect www.yellowlab.tools to yellowlab.tools without "www" (for SEO purpose)
if(/^www\.yellowlab\.tools/.test(req.headers.host)) {
res.redirect(301, req.protocol + '://' + req.headers.host.replace(/^www\./, '') + req.url);
} else {
next();
}
};
module.exports = wwwRedirectMiddleware;