别急别急!我马上就来了!
导航
侧边栏
最新评论
北熙宝宝@Hikurn_Xi管理员
2025-03-26 18:13
@广树:当时顺手在前台回复了。
广树
2025-03-18 20:08
@北熙:🙃所以为什么不是用管理员账号回复
北熙
2025-03-01 12:36
@广树:∠( ᐛ 」∠)_好哦(顺便发现博客的发件系统好像抽风了,评论都没收到邮件,刚刚改了一下。)
北熙宝宝@Hikurn_Xi管理员
2025-03-01 12:25
@leorain:hi,欢迎大佬r入住女子寮。友情链接将会在1h内更新。
2025-02-13 22:04
这番属于看视觉图感觉一般,这些年转生异世界不少厕纸的刻板印象让人感觉应该不会好到哪里去,但是出乎意料的还挺好看。
谷歌广告

如何利用cloudflare批量给图片的链接添加处理参数

作者:北熙宝宝@Hikurn_Xi时间:2024-07-21 22:08:18分类:教程

【前景】

因为最近朋友有个项目把图片迁移到了oss,想着反正都迁移到oss了,顺便用一下图片webp降低一下流量需求。

结果他的程序不支持在url中拼接参数,那么就只能在cdn中实现了。

【准备工作】

打开Cloudflare,选中要修改的域名(如果这个域名是通过SaaS来使用Cloudflare的,请前往你的回退源域名那儿添加)

【方案一:使用页面规则(不推荐)】

在规则--页面规则中,添加,输入域名,比如:

https://yourdomain.com/*/*/*/*.jpg

选择url转发(假设你需要加的参数是!webp

https://yourdomain.com/$1/$2/$3/$4.jpg!webp

测试类型,请务必勾选302!!!在测试没问题后再全量301,谢谢合作!!!!

注意,Cloudflare即将关停页面规则功能,原文:

Cloudflare plans to migrate your existing Page Rules during 2025. You do not need to migrate your own rules, as Cloudflare will handle this process for you. However, it is beneficial to understand the correspondence between the different Page Rules settings and new Rules features ahead of the migration. This will help you familiarize yourself with implementing the new types of rules in your Cloudflare account.
Cloudflare 计划在 2025 年迁移您现有的页面规则。您无需迁移自己的规则,因为 Cloudflare 将为您处理此过程。但是,在迁移之前了解不同的页面规则设置与新规则功能之间的对应关系是有益的。这将帮助您熟悉如何在 Cloudflare 帐户中实施新类型的规则。

We encourage you to explore and start using the new Rules products to take advantage of their enhanced capabilities and features. This migration guide will be updated in the coming months with additional information about the Page Rules migration. Some instructions may also change as we simplify configuration deployment and release new features as part of this project. Cloudflare users will receive email updates about the migration of the Page Rules configured on their Cloudflare account before the migration occurs. We will not perform any migration or changes on your behalf without prior notification.
我们鼓励您探索并开始使用新的 Rules 产品,以利用其增强的功能和特性。本迁移指南将在未来几个月内更新,其中包含有关页面规则迁移的其他信息。随着我们简化配置部署并发布新功能作为此项目的一部分,某些说明也可能会更改。在迁移发生之前,Cloudflare 用户将收到有关迁移在其 Cloudflare 帐户上配置的页面规则的电子邮件更新。未经事先通知,我们不会代表您执行任何迁移或更改。

【方案二:重定向规则(推荐)】

选择自定义匹配规则

当传入请求匹配时...

主机名--->等于--->yourdomain.com

URI--->结尾为--->.jpg


URL 重定向

类型--->动态

表达式--->concat(http.request.uri.path,"!webp")

状态代码--->302  【测试通过后改成301】

建议不要保留查询字符串

【结尾:我应该如何选择?】

如果你希望匹配的有jpg,png,jpeg等多种,而且分布的路径也很复杂,建议直接用方案二,你只需要设置结尾为.文本类型,而且可以用 A and B or A and C....的形式累计,最终生效一个规则!

#cloudflare#OSS#重定向规则#页面规则