[英]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.