浏览代码

Redirect www to non-www for SEO

Gaël Métais 10 年之前
父节点
当前提交
c76711314a
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      server.js

+ 9 - 0
server.js

@@ -22,6 +22,15 @@ app.use(compress());
 app.use(bodyParser.urlencoded({ extended: false }));
 
 
+// Redirect www.yellowlab.tools to yellowlab.tools (for SEO)
+app.all('*', function(req, res, next) {
+    if (req.hostname.match(/^www\.yellowlab\.tools/) !== null ) {
+        res.redirect('http://' + req.hostname.replace(/^www\.yellowlab\.tools/, 'yellowlab.tools') + req.url);
+    } else {
+        next();
+    }
+})
+
 // Routes definition
 app.get('/',                    indexController);
 app.post('/launchTest',         function(req, res) { launchTestController(req, res, testQueue); });