的.htaccess只​​允许访问文件从包括 [英] .htaccess allow access to files only from includes

查看:264
本文介绍了的.htaccess只​​允许访问文件从包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同的子文件夹在我的网站,我想用户不能够通过URL来访问它们,但在同一时间我的主要PHP文件可以包含或将其作为表单或链接动作。

I have various subfolders on my website and I would like for the user not to be able to access them through URL but on the same time my main PHP files to be able to include them or use them as actions on forms or links.

我尝试使用一个.htaccess与

I tried using an .htaccess with

<Files *>
    Order Allow,Deny
    Deny from All
</Files>

但它拒绝所有访问,甚至从我自己的脚本。符合逻辑,因为我发现了,但我不知道如何使它发挥作用。有任何想法吗?

but it denied all access even from within my own scripts. Logical as I found out, but I cannot know how to make it work. Any ideas?

P.S。我最关心的是,一些文件不包含在主PHP文件,但它们与那里的code结束了一个头('位置:../index.php) ;。返回到该项目的主要页面

P.S. My main concern is that some of the files are not included in main PHP files BUT they are linked there and their code ends up with a header('Location: ../index.php'); returning to the main page of the project.

推荐答案

我看到了很多的答案与允许,拒绝不拒绝,允许

I see a lot of answers with Allow,Deny not Deny,Allow

这个问题的顺序,并引起问题。你告诉否认是不是让更重要的计算机,因为它是列在最后。为了向你展示......如果你说:

The order of this matters and is causing the problem. You are telling the computer that deny is more important than allow, because it is listed last. To show you... if you say:

<Files .htaccess>
Order Allow,Deny 
Deny From All
Allow From xxx.xxx.xxx.xxx 127.0.0.1
</Files>

你的意思是先允许任何人允许,然后拒绝所有...这还是拒绝所有。

You are saying first Allow anyone Allowed, then Deny All... Which still Denies ALL.

如果您反向拒绝,允许你在说全部拒绝,则允许任何人允许的。

If you reverse to Deny,Allow you are saying Deny All, then Allow anyone Allowed.

<Files .htaccess>
Order Deny,Allow
Deny From All
Allow From xxx.xxx.xxx.xxx 127.0.0.1
</Files>

允许的命令,是更重要的,因为它是最后的命令,因此允许那些上市之后允许的命令。

Allow command, being more important, because it is the final command, is therefore allowing those listed after Allow From command.

xxx.xxx.xxx.xxx =您的IP

xxx.xxx.xxx.xxx = Your IP

这篇关于的.htaccess只​​允许访问文件从包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆