views:

27

answers:

1

I setup a .htaccess file to require authentication for a directory. I would like to exempt certain files (csv) to avoid some issues with downloading.

I can limit the authentication to the files by doing:

<files ~ "\.csv$">
    require valid-user
</files>

But how can I negate(!) them so ALL files except csv files require authentication?

+1  A: 

This should work:

<files ~ "\..*(?<!csv)$">
    require valid-user
</files>

I've tested this on my local server (Apache 2.2.14) and it works fine. All files except .csv files require authentication before downloading.

Edit
Sorry about all the edits. These sort of regular expressions are always tricky :)

Atli
This doesn't seem to work if you access the directory directly.
Chris Bartow
How do you mean? (By that I mean; how do you access the directory *indirectly*?) - I've tried both of these and they should work. *(Note the edit in the post tho!)*
Atli
The original one would break by going to mydomain.com/dir/ This one seems to work though. Thanks!
Chris Bartow