diff --git a/lib/http-proxy/passes/web-outgoing.js b/lib/http-proxy/passes/web-outgoing.js index 27b794064..67a1a6d98 100644 --- a/lib/http-proxy/passes/web-outgoing.js +++ b/lib/http-proxy/passes/web-outgoing.js @@ -47,7 +47,9 @@ var redirectRegex = /^30(1|2|7|8)$/; }, function setRedirectHostRewrite(req, res, proxyRes, options) { - if (options.hostRewrite && redirectRegex.test(proxyRes.statusCode)) { + if (options.hostRewrite + && proxyRes.headers['location'] + && redirectRegex.test(proxyRes.statusCode)) { var u = url.parse(proxyRes.headers['location']); u.host = options.hostRewrite; proxyRes.headers['location'] = u.format();