拒绝所有配置文件,除了 Apache 中的一个

Emi*_*aos 3 apache .htaccess

我有以下块.htaccess拒绝下载配置文件

# Disables download of configuration
<Files ~ "\.(tpl|yml|ini)$">
    # Deny all requests from Apache 2.4+.
    <IfModule mod_authz_core.c>
          Require all denied
    </IfModule>

    # Deny all requests from Apache 2.0-2.2.
    <IfModule !mod_authz_core.c>
        Deny from all
    </IfModule>
</Files>
Run Code Online (Sandbox Code Playgroud)

但是我怎样才能允许所有命名的文件swagger.yml

Pan*_*ack 5

你应该能够做到这一点

<Files ~ "\.(tpl|yml|ini)$">
    # Deny all requests from Apache 2.4+.
    <IfModule mod_authz_core.c>
          Require all denied
    </IfModule>
    # Deny all requests from Apache 2.0-2.2.
    <IfModule !mod_authz_core.c>
        Deny from all
    </IfModule>
</Files>

<FilesMatch "swagger\.yml$">
       <IfModule mod_authz_core.c>
          Require all granted
       </IfModule>
       <IfModule !mod_authz_core.c>
        Allow from all
    </IfModule>
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

此外,您应该删除未使用的版本的指令。如果您使用的是 2.4,那么您不需要 2.2 指令。但是我离开了它,因为这就是你拥有它的方式。