繁体   English   中英

节点JS重定向循环

[英]Node JS redirection loop

我有这段代码:

app.get('/*', function(req, res, next) {
    res.redirect(301, 'http://example.com' + req.path);
});

和chrome写错误:

“example.com页面无效

example.com重定向了你太多次了。“

有任何想法吗?

您的代码总是重定向您。

您需要添加主机检查器条件。

例如:

app.get('/*', function(req, res, next) {
   if (/^www\./.test(req.headers.host)) {
     res.redirect(301, 'http://example.com' + req.path);
   }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM