How To Protect Original Product Images In Magento 2?

How to protect original product images in Magento 2 tutorial

PROBLEM:

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:

/pub/media/catalog/product/cache/df484df48ez74849c15sd4f7780/f/f/dsf-8f48d4f.jpg

The original image URL without the watermark:

/pub/media/catalog/product/f/f/dsf-8f48d4f.jpg

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?

SOLUTIONS:

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} !^http://www.yourwebsite.com/.*$ [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)$ http://en.wikipedia.org/wiki/You_shall_not_steal [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 *