0

每次将 www.url 匹配到 url 时,我都想重定向我的幽灵应用程序。我找到了这篇两年的帖子并尝试更新代码。我在第一个router.get (管理路由)之前插入了这个片段,但它不起作用。这样做的正确方法是什么?Ghost 版本是 0.7.4。

// 301 redirect from www to non-www
router.get('/*', function(req, res) {
    if(req.headers.host.match(/^www/) !== null) redirect301(res, 'http://' + req.headers.host.replace(/^www\./, '') + req.url);
});
4

0 回答 0