Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If I want to apply a rule to only some files in apache2.conf, I can use <FilesMatch>.

For example:

<FilesMatch ".(gif|jpg|jpeg|png|mpg|avi)$">
    deny from env=hotlink
</FilesMatch>

But is there a opposite to FilesMatch, i.e. a FilesNotMatch?

What I want to achieve is:

<FilesMatch ".(gif|jpg|jpeg|png|mpg|avi)$">
    <FilesNotMatch "ban">
        deny from env=hotlink
    </FilesNotMatch>
</FilesMatch>

(deny hotlinking of all images on a server BUT banners)

Or do you have a suggestion how I could modify my regexp to not match anything that contains "ban" ?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Sadly there doesn't seem to be a way to negate a file match in Apache.

However, the regular expression library that Apache uses is PCRE (Perl Compatible Regular Expressions). This means you have the full power of Perl's regexes, including their negative lookbehind and lookahead assertions. These are fairly complicated and powerful features. I can't be certain that this will work, especially without knowing the full layout of your images, but you might be able to use something like:

<FilesMatch "(?<!ban).*\.(gif|jpg|jpeg|png|mpg|avi)$">
share|improve this answer

Almost correct - you need to use \b(?!.*ban.*)(.+)\.(gif|jpg|jpeg|png|mpg|avi)$ regexp for such exception.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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