在apache2.2中使用Location指令

时间:2017-03-24 02:40:46

标签: apache location directive

我正在尝试下面的内容。尝试了许多方法,但似乎没有任何工作,如果有人有任何想法,请帮助。

<Location /MyRoot>
# '/MyRoot' Should only be allowed, and NONE of its sub should be allowed
# Requests will be redirected to weblogic
</Location>
<Location /MyRoot/MySub1>
# '/MyRoot/MySub1' Should be allowed, and all its sub domains should be allowed
# Requests will be redirected to weblogic
</Location>
<Location /MyRoot/MySub2>
# '/MyRoot/MySub1' Should be allowed, and all its sub domains should be allowed
# Requests will be redirected to weblogic
</Location>

我期待的是

http://host:port/MyRoot/ --- Should be accessible
http://host:port/MyRoot/MySub1 --- Should be accessible
http://host:port/MyRoot/MySub2 --- Should be accessible
http://host:port/MyRoot/MySub1/MySubSub1 --- Should be accessible
http://host:port/MyRoot/MySub1/MySubSub2 --- Should be accessible
http://host:port/MyRoot/MySub2/MySubSub1 --- Should be accessible
http://host:port/MyRoot/MySub2/MySubSub2 --- Should be accessible
http://host:port/MyRoot/MySub1/MySubSub1 --- Should be accessible
http://host:port/MyRoot/MySub1/MySubSub2 --- Should be accessible
http://host:port/MyRoot/ABC --- Should NOT be accessible
http://host:port/MyRoot/XYZ/LKJ --- Should NOT be accessible

MyRoot下可能有很多文件夹我希望它们不可访问(MySub1&amp; MuS)

任何人都可以就如何实现这一目标提出建议。

1 个答案:

答案 0 :(得分:0)

至少我目前所知道,只有根目录上的.htaccess才能实现这一点。

您必须使用以下代码在.htaccess上创建/MyRoot/

Order deny,allow
Deny from all
Allow from 127.0.0.1

避免外部用户列出根目录。然后,在/MyRoot/MySub1/MySubSub1/MyRoot/MySub1/MySubSub2/MyRoot/MySub2/MySubSub1/MyRoot/MySub2/MySubSub2内,您必须连续创建一个.htaccess

Allow from all

这应该在某些方面解决你的问题。希望它有所帮助。