首页 > 解决方案 > htaccess 允许带有正则表达式的文件

问题描述

我正在使用 htaccess 拒绝访问我的 php 文件。不过我需要从外部调用其中一些,例如 index.php

我想出了

<Files a_string_a.php>
Order Allow,Deny
Allow from all
</Files>

按预期工作,我可以使用该文件。但我有几个文件。我想避免为每个文件写一个这样的块。是否有机会解释 htaccess 它将允许访问所有匹配的文件

..._string_.....PHP? (containing a unique string no matter what else is in the filename)

我很确定有一个 RegExpress,但我有点迷茫,没有起诉如何将它集成到 htacess 中 - 谢谢你的提示。

标签: regex.htaccess

解决方案


也许是这样的:

<FilesMatch "(index|foo|bar)\.php$">
  Order Allow,Deny
  Allow from all
</FilesMatch>

并使用 | 添加任何文件基名 (正则表达式或)。

https://httpd.apache.org/docs/2.4/mod/core.html#filesmatch


推荐阅读