Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

(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
up vote 7 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


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.