regex - 如何在 .htaccess 的文件 block 中使用多个路径?

标签 regex apache .htaccess directory

这是我输入 .htaccees 的代码文件:

<Files ~ "\.(php|sql)$">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Files>

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

现在我想在 index.php 旁边添加一个目录路径。所以第二个 block 看起来像这样:

.
.
<Files index.php, /myweb/files>
    Order Allow,Deny
    Allow from all
</Files>

但是这不起作用。注意到<Files index.php | /myweb/files>也不行。正确的语法是什么?


编辑:现在我有两个.htaccess文件。其中之一已进入root:

Options -Indexes

<Files ~ "\.(php|sql)$">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Files>

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

另一个是 /myweb/files文件夹:

Allow from all

但遗憾的是我无法访问.php /myweb/files 中的文件..我怎样才能访问它们?

最佳答案

您需要在 /myweb/files/.htaccess 中使用此代码来允许访问 files/ 中的 *.php 文件目录:

<Files ~ "\.(php|sql)$">
   Allow from all
</Files>

关于regex - 如何在 .htaccess 的文件 block 中使用多个路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46161875/

相关文章:

apache - 如何配置在 docker 容器中运行的 Apache 以同时记录到文件和控制台?

php - 防止直接访问 mp3/wav 文件,同时允许 Flash 播放器使用 .htaccess(或 PHP)访问它们

php - 在 Apache/PHP 中使用 X-Sendfile

apache - htaccess RewriteCond !-f 问题

apache - htaccess 重定向的奇怪行为

apache - .htaccess 文件找不到 404 ErrorDocument

Java 正则表达式、匹配模式、词对

Ruby:如何在正则表达式中匹配双引号

Java 正则表达式 : unexpected char: '('

javascript - JS RegExp catch 单词后面没有括号