我试图在Ubuntu中阻止直接访问某些目录,带有.htaccess的文件。我知道这个问题有很多可能的重复,但它们都没有帮助我。
我的目录结构:
---- /var/www/html
- login.html
- private (folder)
-- content.html
-- css / style1.css , style2.css
-- JS / myscript1.js , myscript.js
现在我想阻止私人文件夹的直接访问。喜欢
10.0.0.1/private - Block or Password required
10.0.0.1/private/css - Block or Password required
10.0.0.1/private/js - Block or Password required
但我需要css ,js
访问login.html
。所以我想允许login.html
的这些私人文件夹访问。
喜欢:
10.0.0.1/index.html - Allow
calling content.html via 10.0.0.1/index.html - Allow
request private/css/style1.css via 10.0.0.1/index.html - Allow
request private/css/style2.css via 10.0.0.1/index.html - Allow
request private/JS/myscript1.js via 10.0.0.1/index.html - Allow
request private/JS/myscript2.js via 10.0.0.1/index.html - Allow
我写这样来阻止私人文件夹访问:
<Directory /var/www/html/private/>
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
当我访问10.0.0.1/private
时,此功能正常。但是,当index.html
请求css , js
时,这会产生问题。
如何处理apache.conf
和.htacess
?我怎么写规则?
有什么建议 ?
答案 0 :(得分:1)
在您要允许的每个文件夹中创建.htaccess
文件(例如:private/css/.htaccess
)
参考:http://httpd.apache.org/docs/2.2/mod/core.html#require
Satisfy Any
Order Allow,Deny
Allow from all
修改强>
删除子目录中的控件
以下示例显示如何使用Satisfy指令 禁用受保护目录的子目录中的访问控制。 应谨慎使用此技术,因为它也会 禁用mod_authz_host强加的任何访问控制。
<Directory /path/to/protected/>
Require user david
</Directory>
<Directory /path/to/protected/unprotected>
# All access controls and authentication are disabled
# in this directory
Satisfy Any
Allow from all
</Directory>