如何防止使用htaccess访问目录? [英] How to prevent access to a directory with htaccess?
问题描述
如何防止访问给定目录?这是我的网站的结构:
How do I prevent access to a given directory ? Here is the structure of my website :
config.php
.htaccess
classes/
|----lib/
| |----...
|----classes.php
webroot/
|----index.php
|----ctrl/
| |----...
|----pages/
| |----...
|----style/
|----...
DocumentRoot
是webroot
.我想禁止访问以下文件夹:ctrl
,pages
,style
.但是存储在这些文件夹中的文件仍然必须可以包含在index.php
文件中.
The DocumentRoot
is webroot
. I want to prohibit access to the following folders : ctrl
, pages
, style
. But the files stored in these folders still have to be available to be included in the index.php
file.
换句话说,有一个index.php
文件.它的作用是从pages/
调用(包括)所有必需的文件,...用户可以从其浏览器加载index.php
,但他们不能单独访问其他文件.
In other words, there is an index.php
file. Its role is to call (include) all the necessary files from pages/
, ... The users can load index.php
from their browser but they cannot access the other files alone.
我写的这段代码是.htaccess
文件,但是它什么也没做:
I wrote this code is a .htaccess
file but it doesn't do anything :
deny from all
<Files webroot/index.php>
allow from all
</Files>
此.htaccess
文件位于我的项目的根文件夹中(在webroot/
之前).我在这里试图做的是拒绝对项目中除主index.php
文件之外的每个目录和文件的访问.
This .htaccess
file is located at the root folder for my project (before webroot/
). What I try to do here is to deny access to every directory and files in the project except for the main index.php
file.
什么是行不通的?出了什么问题?
What is it not working ? What went wrong ?
谢谢.
推荐答案
我解决了这个问题.首先,我必须激活httpd.conf
文件中的.htaccess
文件.然后我在.htaccess
中写了这个:
I solved the problem. First of all, I had to activate .htaccess
files in my httpd.conf
file. Then I wrote this in my .htaccess
:
<Files webroot/pages>
deny from all
</Files>
<Files webroot/style>
deny from all
</Files>
这篇关于如何防止使用htaccess访问目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!