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)

7 Years
Discussion Span
Last Post by lifeworks

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.


Thanks very much!

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

Much appreciated, Ive used the Zend solution

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.