apache filematch: how to match extension except some files

Advertisements

Currently we have:

# ----------------------------------------+++++----
<FilesMatch "(?i)(\.tpl|.twig|\.ini|\.log|\.txt)">
 Require all denied
</FilesMatch>

But we need to allow robots.txt and ads.txt.

How to achieve that?

>Solution :

Try this:

(?i)(\.tpl|.twig|\.ini|\.log|(?<!robots|ads)\.txt)$

(?<!robots|ads)\.txt not robots or ads followed by .txt.

$ the end of the line/string.

See regex demo

Leave a ReplyCancel reply