.htaccess。拒绝根目录,允许特定子文件夹。可能的?
如何拒绝访问 http://sub.mydomain.com/,但允许(完全)< a href="http://sub.mydomain.com/test" rel="noreferrer">http://sub.mydomain.com/test (或 http://sub.mydomain.com/test/)
How can I deny access to http://sub.mydomain.com/, but allow for (completely) http://sub.mydomain.com/test (or http://sub.mydomain.com/test/)
There is a magento back-end behind http://sub.mydomain.com/test/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
.htaccess 指令应用于该目录及其所有子目录,因此您应该禁止在 DocumentRoot 中进行访问,
http://sub.mydomain.com/.htaccess:
并覆盖它在您希望允许访问的任何特定子目录中,
http://sub.mydomain.com/test/ .htaccess:
.htaccess directives apply to that directory, and all subdirectories thereof, so you should disallow access in your DocumentRoot,
http://sub.mydomain.com/.htaccess:
And override that in any specific subdirectories you would like to allow access to,
http://sub.mydomain.com/test/.htaccess:
根目录下的 .htaccess 怎么样,其中包含以下几行?
因此,如果存在“/test/”部分,则不会发生重定向...
How about a .htaccess at the root directory, with the following lines?
So if the '/test/' section is present, no redirect takes place...
尝试在 sub.mydomain.com 中创建 .htaccess 文件以表示拒绝,并在 sub.mydomain.com/test 中创建 .htaccess 文件以表示允许。
或者您可以从 http://sub.mydomain.com/ 重定向以拒绝子目录。
Try create .htaccess file in sub.mydomain.com for deny, and in sub.mydomain.com/test for allow.
Or you can redirect from http://sub.mydomain.com/ to deny subdir.
我知道这是一个非常古老的线程,但我已经为这种情况苦苦挣扎了好几天,终于让它工作了,因此我想我应该分享我的解决方案以供进一步参考。
从 Apache 版本 2.4 开始(我猜),可以使用指令
和
。这可用于允许访问特定的子文件夹。
我的 .htaccess 解决方案(受此网站启发:https:// www.the-art-of-web.com/system/apache-authorization/):
I know this is a very old thread, but I've been struceling with exactly this scenario for several days and finally got it to work, thus I thought I'd share my solution for further reference.
As of Apache version 2.4 (I guess), it's possible to use directive
<RequireAll>
and<RequireAny>
.This can be used to allow access to specific subfolders.
My solution for .htaccess (inspired from this site: https://www.the-art-of-web.com/system/apache-authorization/):
我正在使用 cpanel 支持的服务器,它将添加如下所示的 .htaccess 条目:
我想允许访问特定的子文件夹,解决方案是在该子文件夹中创建一个 .htaccess 文件并将以下内容放入其中:
I'm using a cpanel powered server which will add .htaccess entries like the following:
I wanted to allow access to a specific subfolder, and the solution was creating an .htaccess file within that subfolder and placing the following inside:
如果您已通过身份验证保护您的 DocumentRoot,则可以通过以下方式允许您的子文件夹:
http://sub .mydomain.com/test/.htaccess:
If you have protected your DocumentRoot by Auth, then you can allow your Subfolder by follow:
http://sub.mydomain.com/test/.htaccess: