换域名那次留下了四层跳转。用户点 http://old.Com/a.html,依次经过 http://www.old.com/a.html、https://www.old.com/a.html、https://new.com/a.html,最后落在 https://www.new.com/a.html。curl 测 time_total 0.68 秒,跳转本身占了 0.5 秒。
Google 能跟到第五跳,但每跳都会重新排一次抓取队列,我这边测下来四跳的页面平均收录时间比一跳慢 11 天。百度更保守,超过三跳的链经常只记第一跳。
先量。curl 加 -IL 一次就能看到跳数和每跳耗时,不用装工具。
curl -sIL -o /dev/null -w "%{num_redirects} jumps %{time_total}s
" http://old.example.com/a.html
压平的思路是把中间跳全部合成一跳,直接 301 到终点。Nginx 里用 map 匹配旧域名,用 return 301 代替 rewrite,少一次内部重写。
map $host$request_uri $target {
default "";
"~^old\.com/(.*)" https://www.new.com/$1;
}
server {
if ($target) { return 301 $target; }
}
http 到 https 这一跳省不掉,但证书覆盖裸域名时可以合并:http://old.com 直接 301 到 https://www.new.com,中间不经过 www.old.com。
试过开 HSTS 预加载,只对 http 到 https 有效,域名和 www 这两跳它管不了。也在 CDN 层配过跳转,结果 CDN 和源站各跳一次,反而多一跳,当天回滚。
改完 time_total 0.18 秒,跳数从 4 降到 1。Screaming Frog 爬了 5 万条旧 URL,链式 301 从 3800 条降到 40 条,剩下的是外链直接指向的老路径,改不了。
旧域名至少留一年。301 的信号不是一次性的,外链和收藏夹会持续访问旧地址,撤太早等于把还在传的那部分掐断。
