文件内容
server.js
const http = require('http');
const fs = require('fs');
http.createServer(function(req, res) {
console.log('request come', req.url);
if (req.url === '/') {
res.writeHead(302, {
"Location": "/new",
})
res.end(' ')
}
if (req.url === '/new') {
res.writeHead(200, {
"Content-Type": "text/html",
})
res.end("aaa")
}
}).listen(8888)
console.log('server start at port 8888')
302
每一次请求/,都会先走/,然后再走/new


301
客户端不清除缓存的情况下
- 服务端设置了301之后,只有第一次会先/再转/new
- 以后输入/,都会直接转/new,不会经过/



客户端清除缓存

本文深入探讨了HTTP重定向的工作原理,特别是301和302状态码的区别。通过一个Node.js示例,展示了如何使用这些状态码来实现页面跳转,以及客户端缓存对重定向行为的影响。
710

被折叠的 条评论
为什么被折叠?



