參考:
Express URL跳轉(重定向)的實現:res.location()與res.redirect()
一 方式1
index.js
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(301, {'Location': 'http://itbilu.com/'});
console.log(res._header);
res.end();
});
server.listen(3000);
瀏覽器打開http://127.0.0.1:3000,頁面跳轉到http://itbilu.com。
一 方式2
index.js
var http = require('http');
var server = http.createServer(function (req, res) {
res.redirect('http://itbilu.com/');
//res.redirect(301,'http://itbilu.com/');
res.end(); }); server.listen(3000);
res.redirect更簡便,二者區別?
