how to protect your images on wordpress

Question is, how to protect your images on wordpress. Some time back our server got so much load and bandwidth of server is taken by other websites. preventing images from used by other site is important.

how to protect your images on wordpress

we checked the access to log of my site. we saw the request for my site images through other site. I decided to stop that. Earlier I written good article about this.

https://purabtech.in/protect-images-accessing-server-apache/

I written simple rewrite rule with mod_redirection.

Just open your .htaccess file from your root folder and following code in that.

#Replace ?wordpressapi\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?wordpressapi\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

dont forget to replace your blog name.

 

how to prevent direct access to images through server

how to prevent direct access to images. To protect your images or media file you should use apache rewrite rules. To protect being linked on another website. To protect your images or media file you should use apache rewrite rules. To protect your images or other files from being linked or used on another website. Due the this issue your images may be used by many sites.

how to prevent direct access to images

how to prevent direct access to images
how to prevent direct access to images

The Apache Server’s Mod Rewrite Engine can examine the name of the document requesting a file of a particular type. If the URL of the page requesting the image file is from an allowed domain, display the image. Otherwise, return a broken image.

There are many people who try to use your website images. That will cut your bandwidth so using this code is good idea.

You can use following apache code in apche config file or put following code in your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://images.purabtech.in/.*$     [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purabtech.in/files/.*$ [NC]
RewriteRule .*\.jpg$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://images.purabtech.in/.*$     [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purabtech.in/files/.*$ [NC]
RewriteRule .*\.jpeg$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://images.purabtech.in/.*$     [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purabtech.in/files/.*$ [NC]
RewriteRule .*\.png$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://images.purabtech.in/.*$     [NC]
RewriteCond %{HTTP_REFERER} !^http://www.purabtech.in/files/.*$ [NC]
RewriteRule .*\.gif$
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

Second thing you should do. you should create the dummy index.html file and put in your images folder for so any visitor will not see the directory listing of images.

If you use above code then when other domain try to see or use the your images then they will see the following error message.

it will result in a Forbidden error.
Still if you are having any issue or question then write to me.