Block access to a web subdirectory with .htaccess

◇◆丶佛笑我妖孽 提交于 2020-02-07 21:46:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!