.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.