I need to log downloads to the database, to do this I'm trying to redirect requests for downloads to a template where I can call a custom module function and save info to the db, before providing the original download.

I have the following htaccess, but it just keeps appending to the URL and gives a ';Error: The URL contains too many segments.' error:

RewriteRule ^/downloads/files/(.*)\.zip$ /index.php/log/file_downloads/$1 [L]        

# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png|ico)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

This must be pretty close, any help appreciated!

2 Answers 2


I got it! I think at least some if the problems i had testing various versions of this were down to FF caching

RewriteRule /downloads/files/(.*).zip /index.php/log/file_downloads/$1 [L,R=301]


There are two add-ons available for tracking downloads, so I'd suggest investigating these options before trying to roll your own. They are Link Vault and Protected Links both are quite similar and work very well for what you're looking to do.

  • Thanks, but not an option unfortunately. Most of the code required is already in place, it's just the htaccess that I'm having a problem with.
    – anthiny
    Commented Dec 12, 2013 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.