繁体   English   中英

拒绝使用htaccess直接访问文件

[英]Deny direct access to files using htaccess

我的网站目录结构如下,

/public_html
/public_html/admin/
/public_html/admin/js/
/public_html/admin/css/ ....

基本上我想禁止所有直接访问/ admin子文件夹内的文件,比如不允许直接访问/ js /文件夹中的js但允许它从我的php页面访问

我在/ js /文件夹中添加了以下代码的.htaccess文件,

Order deny,allow
Deny from all

所以它不允许我直接通过浏览器访问它是好的!

但是当我尝试访问index.php页面时,使用标签包含/ js /文件夹的文件,它没有加载。

所以任何人都可以帮助我!

提前致谢。

您没有“从PHP页面”访问它。 Web服务器要么是服务请求,要么不是。 当您在浏览器中加载“PHP页面”时,浏览器将出去并请求从您的页面链接到的所有Javascript,CSS和图像资源。 其中每个都是对Web服务器的单独HTTP请求。 Web服务器没有此HTTP请求的上下文,因为资产是从“您的PHP页面”链接到的,这与它完全无关。 您可以使用HTTP请求从服务器获取文件,也可以不使用。 通过设置Deny from all ,你不能。

您必须通过PHP文件scripts.php?file=js/myscript.js所有请求,该文件检查登录信息,并且仅在用户正确登录时才提供文件。例如链接到scripts.php?file=js/myscript.js并且具有身份验证检查代码scripts.php

限制此类文件夹时,不能在HTML页面中包含其中的文件。 它基本上是相同的请求,就好像该人通过URL直接访问JS一样。

通常是cpanel工具之类的

  1. 热链接保护

    Hotlink protection prevents other websites from directly linking to files (as specified below) on your website. Other sites will still be able to link to any file type that you don't specify below (ie, HTML files). An example of hotlinking would be using an <img> tag to display an image from your site somewhere else on the Web. The end result is that the other site is stealing your bandwidth.

  2. 指数经理

    The Index Manager allows you to customize the way a directory will be viewed on the web. You can select between a default style, no indexes, or two types of indexing. If you do not wish for people to be able to see the files in your directory, choose "No Indexing".

1和2是通常托管cpanel的工具。 可能它写的apache conf文件(不知道哪些)

但是,您还应该了解HTTP referer。 您可以根据此决定何时不显示您的资源。

`HTTP referer is an HTTP header field that identifies the address of the webpage (i.e. the URI or IRI) that linked to the resource being requested`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM