我有以下 .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>
我需要从 auto_prepend 和 auto_append 中排除一个非常具体的目录 '/home/abc/public_html/exclude/`。
可能吗?
最佳答案
.htaccess files - What they are/How to use them解释 .htaccess
文件如何工作
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.
这意味着,您可以在 /home/abc/public_html/
中创建一个 .htaccess 文件,并在 /home/abc/public_html/exclude/
中创建另一个包含以下内容的 .htaccess 文件:相同、不同、甚至矛盾的指令。
查看 PHP - auto_prepend_file
,你可以看到
The special value
none
disables auto-prepending.
这同样适用于auto_append_file
。
将这两件事放在一起意味着,您可以拥有现有的 .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>
以及 exclude
子目录中的第二个 .htaccess
# /home/abc/public_html/exclude/.htaccess
<FilesMatch ".(htm|html|php)$">
php_value auto_prepend_file none
php_value auto_append_file none
</FilesMatch>
关于apache - 如何从 FilesMatch 中排除目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43640403/