使用 .htaccess 或 nginx 配置重写图像规则

Rewrite rule for images using .htaccess or nginx config

我们需要使用 .htaccess 规则或 nginx conf

为一些图像设置重写规则

示例 1

请求路径:

https://www.example.com//media/catalog/product/cache/1/thumbnail/543x403/db978388cfd007780066eaab38556cef/n/u/number1.png

响应路径:

https://www.example.com/pub/media/catalog/product/cache/543x403/n/u/number1.png


示例 2

请求路径:

https://www.example.com/media/catalog/product/cache/1/thumbnail/543x403/db978388cfd007780066eaab38556cef/l/e/legal_slide01.jpg

响应路径:

https://www.example.com/pub/media/catalog/product/cache/543x403/l/e/legal_slide01.jpg


这里的l/e/目录是根据图片名称的前两个字符设置的:legal_slide01.jpg

谢谢

尝试:

rewrite ^/(media/catalog/product/cache)/\d+/thumbnail/(\d+x\d+)/[a-z0-9]+/(\S+) /pub///;

Regex check.