2013-03-17 92 views
2

我正在使用nodejs express。自定义nodejs重定向消息“Moved Temporarily。Redirecting to ...”

对于我的一些网址:res.redirect(new_url, 302);和重定向工作正常。

的问题是服务器发送的消息是“暂时移动。重定向到http://mysite.com/”,我想将其更改为一个简单的正确的HTML,就像谷歌一样。尝试做请求www.google.com(curl www.google.com),您将得到:

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> 
<TITLE>302 Moved</TITLE></HEAD><BODY> 
<H1>302 Moved</H1> 
The document has moved 
<A HREF="http://www.google.co.il/">here</A>. 
</BODY></HTML> 

我甚至找不到在哪里文本的来源。我该如何改变它,以及如何才能做到这一点?

预先感谢您!

+0

备注:例如res.send可以有两个参数:“status”和“body” - 这就是我可以用正确的状态代码和自定义HTML为例404的方式。但res.redirect不幸的是没有“身体”的说法。 – Alexander 2013-03-17 15:17:54

回答

4

使用res.writeHead与所述内容的报头,然后res.end(即HTML):

res.writeHead(302, {'Location': new_url}); 
res.end('<html>...</html>'); 

感谢。