【发布时间】:2016-11-18 08:13:08
【问题描述】:
我试图在 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 ?我该如何写规则?
有什么建议么 ?
【问题讨论】: