Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

html - How to prevent deep linking to files on my website

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 files (for example .zip files) and posting them on their websites and general forums. I am getting a huge amount of bandwidth and that's ok, but the number of pages visited is low. Is there a way or a script that I can add to the links, so that when someone presses on the link from a foreign website, a page from my website opens instead, which then lets him download the file so I can get more visits.

For example, this is a address from my website:

http://sy-stu.org/stu/PublicFiles/StdLibrary/Exam.zip

When anyone presses on it, it will start the downloading process directly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...