How to protect against direct access to images?

前端 未结 9 1068
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 00:47

I would like to create a web site with many images. But I would like to protect against direct access to images, e.g. direct links to images without visiting the web site.

9条回答
  •  没有蜡笔的小新
    2020-12-05 01:39

    Add a simple .htaccess file in your site folder with the follwoing lines

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://www\.your-domain\.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www\.your-domain\.com$ [NC]
    RewriteRule .*\.(wav|swf|jpg|jpeg|gif|png|bmp|js|css)$ - [F,NC,L]
    

    Note I added also js and css file even if I think it's bizzare to find someone who attempts to scrape them.

提交回复
热议问题