我有这段代码:
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);
}
});
关于javascript - Node JS 重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37169542/