Alexander
Alexander

Reputation: 7832

Customize nodejs redirect message "Moved Temporarily. Redirecting to..."

I am using nodejs with express.

For some urls I do: res.redirect(new_url, 302); and the redirection works fine.

The problem is that the message the server sends is "Moved Temporarily. Redirecting to http://mysite.com/" and I'd like to change it to a simple proper html, just like google does. Try to do request to www.google.com (curl www.google.com) and you will get:

<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>

I even can't find where the text is coming from. How can I change it and what is the proper way to do that?

Thank you in advance!

Upvotes: 2

Views: 1689

Answers (1)

Alexander
Alexander

Reputation: 7832

Use res.writeHead with a header then res.end with the content (ie. HTML):

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

Thanks.

Upvotes: 4

Related Questions