2016-11-18 8 views
0

私はいくつかのディレクトリ、Ubuntuで.htaccessでファイルを直接アクセスをブロックしようとしています。私はこの質問に多くの可能性のある重複があることを知っていますが、それらのどれもまだ私を助けませんでした。Apacheで特定のディレクトリ、ファイルの直接アクセスをブロックするにはどうすればよいですか?

私のディレクトリ構造:

---- /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 

のようなしかし、私はlogin.htmlためcss ,jsにアクセスする必要があります。だから私はlogin.htmlのこれらのプライベートフォルダへのアクセスを許可したい。

は次のように:これは正常に動作している

<Directory /var/www/html/private/> 
    AuthType Basic 
    AuthName "Restricted Content" 
    AuthUserFile /etc/apache2/.htpasswd 
    Require valid-user 
</Directory> 

私は10.0.0.1/privateにアクセス:

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 

私はプライベートフォルダのアセスをブロックするために、次のように書きました。しかし、これはindex.htmlcss , jsと要求すると問題になります。

apache.conf.htacessでどうすればいいですか?どのようにルールを書くことができますか? 提案がありますか?

答えて

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> 
+0

ので、私はまた、 '/'/var/www/htmlと設定/プライベートのための私の既存のルールを守る必要がありますか? – user2986042

+0

はい。両方を保つ。 – Rohit

+0

ルールで回答を更新できますか? – user2986042

関連する問題