问题
My directory:
/root/
/root/directory1/
/root/directory2/
If the .htaccess file is located inside root,
How do I deny access to directory1
while allowing access to directory2
Could you please help by being precise? I am a total beginner, the office's pro is on vacation :) May thanks in advance!
回答1:
The tl;dr version is below however it is better to learn how to fish. Thus rtfm so one knows what to do instead of always asking for the answer.
I suggest reading up on how to use .htaccess to block access to a resource and how to deny directory index. Also one needs to ensure that .htaccess files cannot be directly accessable with an absolute url.
Therefore your .htaccess should look something like the following:
#/root/.htaccess - override any .htaccess in /directory1 and /directory2
# prevent listing of directory contents
Options -Indexes
# block .htaccess from being read
<Files .htaccess>
order allow,deny
deny from all
</Files>
<Directory "/directory1">
order deny,allow
deny from all
</Directory>
回答2:
Inside /directory1/.htaccess place this line:
Deny from all
to block all access to directory1.
来源:https://stackoverflow.com/questions/30333673/block-access-to-a-web-subdirectory-with-htaccess