How to protect against direct access to images?

前端 未结 9 1063
没有蜡笔的小新
没有蜡笔的小新 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:23

    This might be useful: Allow/deny image hotlinking with .htaccess

    Edit: One thing to note about this method is that some Browser/AV/Firewall software removes Referer data when you browse, which would cause potentially legitimate users to be treated as hotlinkers.

    If your site already uses some kind of authentication or session system, then it would be better to use the method given in @Mark Baijens' answer.

    Update: NGiNX rewrite rule to prevent hotlinking:

    location ~* (\.jpg|\.png|\.css)$ {
        valid_referers blocked mydomain.com www.mydomain.com;
        if ($invalid_referer) {
            return 444;
        }
    }
    

提交回复
热议问题