Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a directory from FilesMatch

I have the following .htaccess directive:

<FilesMatch ".(htm|html|php)$">
  php_value auto_prepend_file "/home/abc/public_html/_prepend.php"
  php_value auto_append_file "/home/abc/public_html/_append.php"
</FilesMatch>

I need to exclude a very specific directory '/home/abc/public_html/exclude/` from the auto_prepend and auto_append.

Is it possible?

like image 729
H. Ferrence Avatar asked Apr 26 '17 17:04

H. Ferrence


1 Answers

.htaccess files - What they are/How to use them explains how .htaccess files work

A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

This means, you can create a .htaccess file in /home/abc/public_html/, and another one in /home/abc/public_html/exclude/ containing the same, different, or even contradicting directives.


Looking at PHP - auto_prepend_file, you can see that

The special value none disables auto-prepending.

The same applies to auto_append_file.


Putting these two things together means, you can have the existing .htaccess

# /home/abc/public_html/.htaccess
<FilesMatch ".(htm|html|php)$">
  php_value auto_prepend_file "/home/abc/public_html/_prepend.php"
  php_value auto_append_file "/home/abc/public_html/_append.php"
</FilesMatch>

and a second .htaccess in the exclude subdirectory

# /home/abc/public_html/exclude/.htaccess
<FilesMatch ".(htm|html|php)$">
  php_value auto_prepend_file none
  php_value auto_append_file none
</FilesMatch>
like image 123
Olaf Dietsche Avatar answered Oct 14 '22 00:10

Olaf Dietsche