gpt4 book ai didi

node.js - 自定义nodejs重定向消息 "Moved Temporarily. Redirecting to..."

转载 作者:搜寻专家 更新时间:2023-11-01 00:33:39 25 4
gpt4 key购买 nike

我正在使用 nodejs 和 express。

对于某些网址,我这样做: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>

我什至找不到文本的来源。我怎样才能改变它,什么是正确的方法?

提前致谢!

最佳答案

res.writeHead 与标题一起使用,然后将 res.end 与内容(即 HTML)一起使用:

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

谢谢。

关于node.js - 自定义nodejs重定向消息 "Moved Temporarily. Redirecting to...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15462175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com