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

问题描述 投票:0回答:1

我们需要使用.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

谢谢

.htaccess nginx mod-rewrite url-redirection http-status-code-301
1个回答
1
投票

尝试:

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

Regex check

© www.soinside.com 2019 - 2024. All rights reserved.