Saturday, May 17, 2014

Restrict image access from browser using HTACCESS



 When we want to restrict the image access from the browser other than the page, add the below code in htaccess file to apply.


RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(gif|jpg|png)$ - [F]

localhost need to be replaced by the domain name where the application is hosted. 

NOTE: Above code works in Apache (LINUX) not in windows