.htaccess - 使用 .htaccess 仅授予对一个目录的访问权限

标签 .htaccess

我只想提供对单个目录 (/dist) 的公共(public)访问。我有一个包含以下内容的 .htaccess 文件:

Order deny,allow
Deny from all

<Directory /dist>
    Order Allow,Deny
    Allow from all
</Directory>

我试图首先拒绝所有访问,然后用/dist 目录的允许规则覆盖该指令。但是,当我尝试通过浏览器访问任何文件时,我得到以下信息:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at you@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

我做错了什么?

最佳答案

正如@Anubhava 所说,目录指令在 htaccess contex 中是不允许的,该指令只能在目录上下文中使用。您可以使用 RewriteRule 拒绝访问除/dist 目录之外的所有目录:

RewriteEngine on

RewriteRule !dist - [F]

这将禁止除/dist 请求之外的所有传入请求。

关于.htaccess - 使用 .htaccess 仅授予对一个目录的访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44024222/

相关文章:

regex - 301 将所有博客文章重定向到新的子文件夹

wordpress - 子域上的 https 重定向到主域;子域在没有 https 的情况下工作

svn - 我怎样才能说服 mod_rewrite 远离我的 Subversion 存储库?

.htaccess - mod_deflate和mod_header设置?

regex - .htaccess RewriteRule 正则表达式匹配特定单词

java - 使用 Apache Server 为在 Tomcat 中运行的网站设置重定向

php - Laravel 将 .html 附加到路由(并且也可以在没有 .html 的情况下工作)

.htaccess - 允许从代码访问文件,但阻止从浏览器访问?

php - .htaccess 在 SSL/端口 443 下被忽略

.htaccess 在我的 PHP MVC 框架中不起作用