.htaccess拒绝子文件夹中的文件

Hal*_*yon 12 php apache .htaccess

我想阻止访问"sub/folder/index.php",但不能阻止访问"index.php".

<Files index.php>
    Order allow,deny
    Deny from all
</Files>
Run Code Online (Sandbox Code Playgroud)

但可以阻止所有"index.php"文件.

<Files sub/folder/index.php>
    Order allow,deny
    Deny from all
</Files>
Run Code Online (Sandbox Code Playgroud)

不起作用.我需要使用<Directory>吗?

我不想在子/文件夹中创建.htaccess文件

我无法访问httpd.conf

我不想阻止子/目录中的所有内容

如果这很容易,我不会问;)

reg*_*ero 23

我认为最简单的规则是:

RedirectMatch 403 ^.*/sub/folder/index\.php$
Run Code Online (Sandbox Code Playgroud)

RedirectMatch在mod_alias模块中,你当然有.这并不意味着mod_rewrite引擎.这里我们只是告诉apache对sub/folder/index.php的任何访问都会生成"403禁止"的答案.

你可以把它放在httpd.conf或root .htaccess中(但是真的考虑删除所有的.htaccess,它很糟糕,它很慢,很遗憾你无法访问真实的配置文件).