Block access to a web subdirectory with .htaccess

2019-09-10 06:19发布

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!

标签: .htaccess
2条回答
姐就是有狂的资本
2楼-- · 2019-09-10 06:43

Inside /directory1/.htaccess place this line:

Deny from all

to block all access to directory1.

查看更多
Summer. ? 凉城
3楼-- · 2019-09-10 06:45

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>
查看更多
登录 后发表回答