How to prevent deep linking to files on my website

后端 未结 5 932
名媛妹妹
名媛妹妹 2020-12-17 20:34

I own a website which contain a lot of freeware stuff to download on it. The problem I\'m facing is that people from around the world are taking the direct links of the fil

5条回答
  •  太阳男子
    2020-12-17 20:55

    Your site is hosted by an Apache web server, so you should be able to do the following in your site's httpd.conf (or virtual host block)

    RewriteEngine On
    RewriteCond   %{HTTP_REFERER} !^$
    RewriteCond   %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/  [NC]
    RewriteRule   ^/PublicFiles/  /page-about-direct-links.html
    

    That is basically saying:

    1. Turn the mod_rewrite engine on
    2. If the HTTP Referrer is not blank…
    3. And doesn't contain my domain name (with or without “www.”)…
    4. Redirect any requests for anything under /PublicFiles/ to /page-about-direct-links.html

    More information on mod_rewrite can be found here: mod_rewrite - Apache HTTP Server

提交回复
热议问题