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 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't seem to work if you access the directory directly.
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!)
The original one would break by going to mydomain.com/dir/ This one seems to work though. Thanks!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.