PHP code for anti hotlinking

前端 未结 6 1161
深忆病人
深忆病人 2020-12-03 09:26

In our sites we are doing a image protection section. So as a part of image protection we need provide antihotlinking for images.In our site we are showing the image using a

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 09:56

    basic .htaccess example

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
    

    above allows a blank REFERER (like me).

    this does not:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
    

    there are quite a few variations you can find, may need to play around a bit to find what is best for you.

提交回复
热议问题