如果您使用的 Caddy Web 服务器不支持 .htaccess 规则, Xilifox Image Optimizer 插件需要额外配置才能正常工作.
-
步 1. #
启动与您网站的 SSH 连接 或将此说明转发给您的服务器管理员.
-
步 2. #
使用命令进入主机配置目录:
cd /etc/caddy使用命令编辑配置文件:
nano Caddyfile -
步 3. #
在配置文件中, 找到负责您的域的块并在其中添加以下规则:
# BEGIN XIO
header /wp-content/*/*.jpg Cache-Control "private"
header /wp-content/*/*.jpeg Cache-Control "private"
header /wp-content/*/*.png Cache-Control "private"
header /wp-content/*/*.webp Cache-Control "private"
@acceptsAvif {
header Accept *image/avif*
path_regexp avif ^/wp-content/(.+)/(.+)\.(jpg|jpeg|png|webp)$
}
@acceptsWebp {
header Accept *image/webp*
path_regexp webp ^/wp-content/(.+)/(.+)\.(jpg|jpeg|png)$
}
handle @acceptsAvif {
@hasAvif file /wp-content/uploads-xio/{re.avif.1}/{re.avif.2}.{re.avif.3}.avif
rewrite @hasAvif /wp-content/uploads-xio/{re.avif.1}/{re.avif.2}.{re.avif.3}.avif
}
handle @acceptsWebp {
@hasWebp file /wp-content/uploads-xio/{re.webp.1}/{re.webp.2}.{re.webp.3}.webp
rewrite @hasWebp /wp-content/uploads-xio/{re.webp.1}/{re.webp.2}.{re.webp.3}.webp
}
# END XIO请记住:
- 在负责您的域的块中添加规则
- 如果您有多个块负责您的域 (例如. HTTP 和 HTTPS 分开), 在所有块中添加规则
- 在块中的其他指令之前添加这些规则
-
步 4. #
使用命令重新启动Caddy服务器:
service caddy restart
