Node.js server “404 not found” message to 404.html page

前端 未结 5 1884
南旧
南旧 2021-01-04 16:50

Im working with node.js and I would like to know how to display a 404.html instead of a \"404 Not Found\" message.

This is my server.js:

var http = r         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 17:18

    response.writeHead(404, {
      'Location': 'your/404/path.html'
      //add other headers here...
    });
    response.end();
    

    or with a single line

    response.redirect('your/404/path.html');
    

提交回复
热议问题