.htaccess阻止直接访问子目录,但允许通过JQuery/images/etc调用它们 [英] .htaccess Block direct access to subdirectories, but allow them to be called via JQuery/images/etc

查看:179
本文介绍了.htaccess阻止直接访问子目录,但允许通过JQuery/images/etc调用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要index.php通过JQuery从子目录调用了几个脚本.我需要阻止直接访问此目录中的任何文件,但允许通过index.php访问它们.我已经尝试了简单的方法:

My main index.php calls a couple of scripts via JQuery from a subdirectory. I need to block direct access to any files in this directory, but allow them to be accessed by index.php. I have tried the simply:

deny from all

方法,但这甚至阻止了Jquery加载脚本.还有一个/images子目录,需要禁止其直接访问. deny all禁止以任何方式调用该图像.有人知道该怎么做吗?

approach, but this blocks even Jquery from loading the script. There is also an /images subdirectory that needs to be blocked from direct access. deny all disallows the image from being called in any way. Does anyone know how to do this?

推荐答案

仅使用php的文件功能来获取受保护文件的内容,因此只有您的php文件(例如index.php)能够处理带有受保护目录的文件.

just use the file-functions of php to get the content of the protected files, so only your php-file (e.g. index.php) is able to handle with the files of the protected dir.

有用的功能是:

file_get_contents()

fread()

...

然后,您可以在输出HTML中包含js代码,或将内容显示为图像(然后,请查看

then you can include the js-code in your output-html or get the content out as image (then you should take a look at the header() function.

这篇关于.htaccess阻止直接访问子目录,但允许通过JQuery/images/etc调用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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