我已经尝试将其写入我的配置文件,以仅匹配该“示例”目录中的文件夹,而不匹配其他子文件夹...
<DirectoryMatch "\/var\/www\/html\/example\/[^/]+\/">
IndexIgnore ..
</DirectoryMatch>
我试过的其他正则表达式...
/var/www/html/example/[^/]+/
/var/www/html/example/(.+/){1}
如果我明确写下文件夹的路径,它就可以工作。我哪里错了?
我看到 Apache 使用 PCRE 提供的 Perl 兼容正则表达式图书馆。
服务器版本:Apache/2.4.18 (Ubuntu)
服务器构建:2016-07-14T12:32:26
最佳答案
/
不需要转义。使用 ^
和 $
标记匹配路径的开始和结束。尾部斜杠必须是可选的 (/?
)。
<DirectoryMatch "^/var/www/html/example/?$">
...
</DirectoryMatch>
或
<DirectoryMatch "^/var/www/html/example/[^/]+/?$">
...
</DirectoryMatch>
关于regex - 如何为 Apache 'DirectoryMatch' 编写格式正确的正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41708810/