tags:

views:

140

answers:

3

Hi Guys,

I've been trying without success to get a rule working on my production server that works fine on my WAMP server on my local machine:


    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule \.exe /download/ [L]

On my local server it redirects all direct file download requests to /download/ but on the production server the files are just downloaded, if you remove the condition and type a non-existant file name it does redirect to /download/..

Once i've got this working i'm going to add an additional condition that the referer must be something like /download/ok/ for it to download the file.

+1  A: 

Try adding this line on top:

Options +FollowSymlinks

so...

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.exe /download/ [L]

This is a good guide: http://corz.org/serv/tricks/htaccess2.php

Sam
Hi Sam, thanks for the suggestion, i've tried that and no different :(, that guide is cool though! its anwsered another question i was trying to find the answer to :)
Dean Bayley
A: 

Try to find out what value %{REQUEST_FILENAME} has:

RewriteCond %{QUERY_STRING} ^$
RewriteRule \.exe %{REQUEST_URI}?%{REQUEST_FILENAME} [R]

Maybe you need to compose the correct file system path yourself:

RewriteCond %{DOCUMENT_ROOT}$0 -f
RewriteRule .*\.exe.* /download/ [L]
Gumbo
Hi Gumbo,Tried that and still doesn't work, i don't think the rule is wrong i think for some reason mod_rewrite isn't being used if the file exists..In the site config is states:<pre><code> <Directory /home/virtual/site1/fst> Options -FollowSymlinks +SymlinksIfOwnerMatch </Directory></pre></code>
Dean Bayley
Have you checked what value REQUEST_FILE has and if that value is correct?
Gumbo
http://www.domain.com/download/fake.exe?/home/virtual/site1/fst/var/www/html/download/fake.exe
Dean Bayley
So that path is correct?
Gumbo
A: 

The download must of been coming from the cache!

I feel really stupid now, i've spent countless hours on this and all this time it was a cache problem, i cleared the firefox cache and it works fine..

I settled on:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{HTTP_COOKIE} !^.*download_key=abc123.*$
RewriteRule \.exe /download/ [R]

Dean Bayley