we need to set rewrite rule for some images in Magento 2.2.5
using .htaccess rules or nginx conf
Example 1
Request Path:
Response Path:
https://www.example.com/pub/media/catalog/product/cache/543×403/n/u/number1.png
Example 2
Request Path :
Response Path :
https://www.example.com/pub/media/catalog/product/cache/543×403/l/e/legal_slide01.jpg
Here the l/e/
directories are set according to the first two characters of image name here: legal_slide01.jpg
Thank you
Best Answer
You can use the following RewriteRule in the
.htaccess
file inside themedia
folder. Just add this two lines right belowRewriteEngine on
:This rule will do a 301 redirect, if you just want to serve the imagase with the original URL and do an internal redirect, just remove
R=301
from the rule's options.I hope that helps