homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Using .htaccess to prevent file leeching

 11:46 am on May 20, 2003 (gmt 0)

I have been having trouble with sites leeching the files from my page. My files are mainly exe, zip, and rar files. All the posts I see about .htaccess has to do with images. Is there a way to prevent direct linking to my files? I copied a .htaccess from one of the posts and changed it around and it didn't work. This is what I used:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.net [NC]
RewriteRule .*\.(exe¦zip¦rar)$ - [F]

I uploaded it to my downloads folder. I am such a noob to this, so any help would be appreciated.


[edited by: DaveAtIFG at 3:53 pm (utc) on May 20, 2003]
[edit reason] Domain name revised [/edit]



 3:26 pm on May 20, 2003 (gmt 0)


Your code is basically correct. Make sure you have spaces in front of the exclamation point "!" characters as shown and that you are using a solid pipe character instead of a broken pipe like this "¦" one - Posting code on the forum causes both of these problems. Note that ".*" at the begining of an unanchored pattern is not needed.

Also, try adding the Options directive as shown.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.net [NC]
RewriteRule \.(exe¦zip¦rar)$ - [F]
You might want to check your raw error log file after testing this rewrite - sometimes it will give you a very good hint if there is a problem.

If this doesn't work, you may not have access to mod_rewrite, or have the required priveleges to run it. Contact your hosting service and ask them.



 4:48 pm on May 20, 2003 (gmt 0)

Well, I copied the code that you had in the last post. I uploaded it to my download directory and I don't get any errors this time but I still can download from other site. Would not having access to the mod_rewrite be the problem?

Thanks for your response



 5:05 pm on May 20, 2003 (gmt 0)

Could be - check with your host about what they allow or don't allow.


 6:31 pm on May 20, 2003 (gmt 0)


Also, make sure you are clearing your browser cache (Temporary Internet Files) between tests! That's the number one problem most folks have when testing. If you already have a copy of the requested file in your cache, the request never gets to your server, so it can't be blocked.



 6:51 pm on May 20, 2003 (gmt 0)

Well I cleared the cache, and contacted my host. My host said that Frontpage extensions were on and needed to be disabled. Which they are disabled now, but my download .htaccess file in my download directory still doesn't prevent leeching. Should I change the .htaccess file in my public_html directory. This the email:

"FP ext. disbaled.

Delete exisitng .htaccess file and create your own in /var/www/html"

So my .htaccess in that directory is any good now?

Told you Iam a total noob, but thx for the replies.



 7:18 pm on May 20, 2003 (gmt 0)


Your code should work either in your downloads directory or in your root (home page) directory.

Clear the cache before every test to get consistent results.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved