设置“.htaccess”指令后,可以覆盖它吗?

设置“.htaccess”指令后,可以覆盖它吗?

我正在使用HTML5 样板 .htaccess,其中包含用于保护隐藏文件和文件夹的部分:

# Block access to all hidden files and directories with the exception of
# the visible content from within the `/.well-known/` hidden directory.
#
# These types of files usually contain user preferences or the preserved
# state of an utility, and can include rather private places like, for
# example, the `.git` or `.svn` directories.
#
# The `/.well-known/` directory represents the standard (RFC 5785) path
# prefix for "well-known locations" (e.g.: `/.well-known/manifest.json`,
# `/.well-known/keybase.txt`), and therefore, access to its visible
# content should not be blocked.
#
# https://www.mnot.net/blog/2010/04/07/well-known
# https://tools.ietf.org/html/rfc5785

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
</IfModule>

我想添加另一个文件夹以将其排除在外,但理想情况下,我想避免编辑 HTML5 Boilerplate 提供的代码。

在的末尾.htaccess,我如何添加一个指令来否定特定文件夹的上述条件,例如.example

答案1

由于您的根.htaccess文件使用 mod_rewrite 来阻止访问,您只需.htaccess在您想要允许访问的文件夹中创建另一个文件(例如/.example/.htaccess)并启用重写引擎:

RewriteEngine On

默认情况下,mod_rewrite 指令不会被继承,因此只需在子目录中启用重写引擎即可覆盖父.htaccess文件中的所有 mod_rewrite 指令。父文件中的 mod_rewrite 指令.htaccess甚至不会被处理。

相关内容