How To Protect Original Product Images In Magento 2?

How to protect original product images in Magento 2 tutorial


The developer enables the watermark function of Magento 2, but the original product images are still accessible from the URL without the watermark.

For example:

Cached image URL with the watermark:


The original image URL without the watermark:


Therefore, if someone who removes /cache/df484df48ez74849c15sd4f7780/ from URL can still access the original photo without a watermark to steal the images.

How can the developer protect his original product images?


The simple solution here is modifying and using the following .htaccess file in the /var/media/catalog directory:

Options +FollowSymLinks
RewriteEngine on

#The next coding line permits the original images to be accessed by admin end directly

RewriteCond %{HTTP_REFERER} !^*$ [NC]

#The next coding line permits the watermarked images to be accessed directly. It is according to the rule where the URL does not contain a cache.

RewriteCond %{REQUEST_URI} !(/cache/) [NC]

#It is the page where your store visitor will be redirected if they will attempt to access images directly.

RewriteRule \.(gif|jpg)$ [R,L]

The above security measure will help the developer to prevent his Magento product images from being stolen, downloaded, and copied.

We have shown you an easy way to protect the original image files in Magento 2. If you have any problems when following the instruction, please leave a comment below. See you in the next tutorial!

Related Posts:

[Solved] Magento “One Or More Indexers Are Invalid” Error

Magento Image Optimization: A Complete Guide for Store Owners

10 Powerful Applications Of Artificial Intelligence In Magento Stores

How To Create Order Programmatically In Magento 2

Leave a Reply

Your email address will not be published. Required fields are marked *