165 字
1 分钟
解决 Cloudflare Workers 访问不带斜杠的 URL 返回 307 的问题
起因
今天看 Google Search Console 时,突然发现了这个

于是找Opencode排查了下 (Opencode 说的话看看就好)

终于知道为啥子目录都没被收录了😅
解决
知道了原因,解决起来就比较简单了
在 Cloudflare 创建这样一条重定向规则

(not ends_with(http.request.uri.path, "/")) and (not http.request.uri.path contains ".") and (http.request.uri.path != "/")重定向到
concat("你的域名", http.request.uri.path, "/")这样在 Worker 之前抢先 301 重定向
使curl测试
可以看到不带/ 的链接被正确 301 重定向了

就这样吧,希望过几天能被谷歌正常收录
参考资料
https://hitoritech.com/blog/how-to-fix-google-search-console-redirect-errors/
解决 Cloudflare Workers 访问不带斜杠的 URL 返回 307 的问题
https://silongj.us.ci/posts/cf-307-fix/