文件内容

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
clipboard.png

clipboard.png

clipboard.png

301

客户端不清除缓存的情况下

  1. 服务端设置了301之后,只有第一次会先/再转/new
  2. 以后输入/,都会直接转/new,不会经过/

clipboard.png

clipboard.png

clipboard.png
客户端清除缓存

clipboard.png


渣渣辉
1.3k 声望147 粉丝