How to prevent a file from direct URL Access?

后端 未结 7 2030
后悔当初
后悔当初 2020-11-22 05:26

I\'m using Apache and I have a sample web folder on my Local Host, like:

      http://localhost/test/

Files in th

7条回答
  •  渐次进展
    2020-11-22 06:15

    Try the following:

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

    Returns 403, if you access images directly, but allows them to be displayed on site.

    Note: It is possible that when you open some page with image and then copy that image's path into the address bar you can see that image, it is only because of the browser's cache, in fact that image has not been loaded from the server (from Davo, full comment below).

提交回复
热议问题