How to prevent a file from direct URL Access?

后端 未结 7 2028
后悔当初
后悔当初 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:08

    rosipov's rule works great!

    I use it on live sites to display a blank or special message ;) in place of a direct access attempt to files I'd rather to protect a bit from direct view. I think it's more fun than a 403 Forbidden.

    So taking rosipov's rule to redirect any direct request to {gif,jpg,js,txt} files to 'messageforcurious' :

    RewriteEngine on 
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.ltd [NC] 
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.ltd.*$ [NC] 
    RewriteRule \.(gif|jpg|js|txt)$ /messageforcurious [L]
    

    I see it as a polite way to disallow direct acces to, say, a CMS sensible files like xml, javascript... with security in mind: To all these bots scrawling the web nowadays, I wonder what their algo will make from my 'messageforcurious'.

提交回复
热议问题