954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

htaccess file downlaods

Hi

I wasnt sure where to stick this, so Im asking this crowd

I am putting together a website which works on an MVC principle, my own framework, and need some help with the .htaccess file.

Specifically, if I want to make a pdf available for download, my url parser is treating the request for the file like any other visitor on the website and naturally coming into some trouble as a result.

I tried setting a rewrite rule for files of a certain type,

RewriteCond %{REQUEST_URI} !public/files
RewriteRule ^(.*\.(pdf|txt|doc|xls|ppt|pptx|xlsx|docx|psd|ai|cdr))$ public/files/$1 [L,PT]


but thats going to mess with every link thats one of those filetypes - is there a better option? something which will allow all requests for files from the public/files directory to not be redirected to my controller...? (index.php)

lifeworks
Junior Poster
145 posts since Nov 2007
Reputation Points: 15
Solved Threads: 2
 

I believe what you're looking for is something like the following

RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php


Where any request which is not for a file of those types is routed to index.php (You would need to add pdf to that)

But I think a better solution would be to use something like the Zend Framework does:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]


Which basically says if the requested file is not a directory, file (with size) or symbolic link, rewrite it to index.php.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

Thanks very much!

Seems to be working fine, the download is working at least :)

Much appreciated, Ive used the Zend solution

lifeworks
Junior Poster
145 posts since Nov 2007
Reputation Points: 15
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: