我正在使用nodejs与express。
对于某些url,我使用:res.redirect(new_url, 302);
,重定向工作良好。
问题是服务器发送的消息是"Moved Temporarily"。重定向到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>
我甚至找不到文本是从哪里来的。我怎样才能改变它,正确的方法是什么?
提前感谢!
使用res.writeHead
与标题,然后res.end
与内容(即。HTML):
res.writeHead(302, {'Location': new_url});
res.end('<html>...</html>');
谢谢。